【发布时间】:2011-06-02 04:20:41
【问题描述】:
我正在尝试让 Apache 2.2 mod_rewrite 获得干净的 url。 我有诸如
之类的链接<ul>
<li><a href="index.php?view=pageName">Page Name</a></li>
<li><a href="index.php?view=pageName2">Page Name2</a></li>
<li><a href="index.php?view=pageName3">Page Name3</a></li>
</ul>
然后 url 出来了
http://example.com/user/index.php?view=pageName
我想把地址栏中的url清理成这个
http://example.com/user/pageName
编辑:如果有用的话,这就是我的 httpd.conf 中的内容。
<Directory "C:/Apache2.2/htdocs/user">
Options Indexes FollowSymLinks
AllowOverride all
order allow,deny
Allow from all
</Directory>
使用 phpinfo() 我已验证 mod_rewrite 已加载,并且我的 .htaccess(用户文件,不是 root .htaccess)中有这个,而不是 apache 上的虚拟用户
RewriteEngine on
RewriteBase /user/ #Edited rewrite base added in, but not helping much.
RewriteOptions Inherit
RewriteRule ^/user/([a-zA-Z])/?$ index.php?view=$1 [NC,L]
编辑:我的 .htaccess 的其余部分
#Ensure browser reads Header
Header unset ETag
FileETag None
Header unset Last-Modified
#Set caching expires
Header set Expires On
ExpiresDefault "access plus 30 days"
#gzip
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
在所有 html 结构相同的菜单链接上的工作方式不同,并且无法正常工作。 IE:它将我发送到http://example.com/user/?view=pageName,但正在加载根 HTML 文件内容。
如果我改变这一行
RewriteRule ^/user/([a-zA-Z])/?$ index.php?view=$1 [NC,L]
到
RewriteRule ^index\.php$ http://www.google.com [NC,L]
我按预期被发送到谷歌。所以很明显我在匹配和替换方面做错了什么,但我做错了什么? 提前致谢。
编辑: access.log 和 error.log 没有错误。
【问题讨论】:
标签: php apache mod-rewrite clean-urls