dsizmmwnm56437180 2014-07-31 12:26
浏览 30

像Drupal一样干净的URL系统

I've been hired to re-factor some homemade websites. Those websites are made in the good old fashion way: one page = one php file with header, content, script, footer. Now my client wants to update the layout of all the pages I feel like DRYing a bit the code by creating a clean URL system. Instead of :

example.com/page1.php, example.com/page2.php

I'd like to have:

example.com/page1, example.com/page2

Where the two pages call the same php file just charging the content of the page.

My questions are: 1. how to catch the URL and converts it into parameters? 2. how to avoid the website default behavior to search in directory /page1 or /page2?

  • 写回答

1条回答 默认 最新

  • dragonlew9876 2014-07-31 13:20
    关注

    If you are using the Apache web server, you can read-up on Multiviews. While normally used to serve up the same page in different languages, its effect is that whenever you specify a name without an extension, and that name isn't already a folder, then the file with the same name will be served.

    For example, you ask for http://localhost/example, and example isn't a folder name, then if example.php exists, it will be served up instead. You just have to make sure you don't have two or more files with the same name and different extensions, or a folder and file with the same name.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能