【发布时间】:2013-12-08 04:09:22
【问题描述】:
我正在尝试使使用 apache mod_rewrite 的 SEO 友好 URL。
我的正常网址是这样的 -
index.php?p=about
index.php?p=contact
index.php?p=this
我期望的 SEO 友好 URL 应该与此类似 -
localhost/php_advance/ch02/about
localhost/php_advance/ch02/contact
localhost/php_advance/ch02/this
我尝试创建一个.htaccess 文件并对我的apache httpd.conf 文件进行一些更改。
这是我的 .htaccess 文件
<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Set the base to this directory:
RewriteBase /php_advance/ch02/
# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
</ifModule>
另外,在httpd.conf 文件的末尾,我添加了一些这样的代码 -
<Directory "C:/wamp/www/php_advance/ch02">
AllowOverride All
</Directory>
NOTE:我正在使用 WAMP 服务器和 Windows 07
但是这种编码对我不起作用。希望有人能帮助我。 谢谢你。
【问题讨论】:
-
@anubhava,不,我不能得到 404。当我在浏览器地址栏上输入
http://localhost/php_advance/ch02/about时,我可以得到这个Not Found The requested URL /php_advance/ch02/about was not found on this server. -
试试这条规则来测试:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1 [L,R] -
@anubhava 我检查了,但仍然无法正常工作。
-
似乎 .htaccess 未启用。在上面放一些垃圾文本,看看会不会产生500(内部服务器)错误
-
需要在哪个页面添加垃圾文字? .htaccess 或 ???
标签: php apache .htaccess mod-rewrite friendly-url