Apache 2.2 mod_rewrite 帮助
我正在尝试让 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 没有错误。
I am trying to get Apache 2.2 mod_rewrite to get clean urls.
I have links such as
<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>
and url comes out to be
http://example.com/user/index.php?view=pageName
I would like to clean the url in the address bar it to this
http://example.com/user/pageName
Edit: This is what's in my httpd.conf if it's any use.
<Directory "C:/Apache2.2/htdocs/user">
Options Indexes FollowSymLinks
AllowOverride all
order allow,deny
Allow from all
</Directory>
Using phpinfo() I have verified that mod_rewrite is loaded and I have this in my .htaccess (user file, Not root .htaccess) and not virtual user on 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]
Edit: the rest of my .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>
does not work the same on all menu links which are identical in html structure, and not working properly. IE: It sends me to http://example.com/user/?view=pageName
, but is loading the root HTML file content.
If I change this line
RewriteRule ^/user/([a-zA-Z])/?$ index.php?view=$1 [NC,L]
to
RewriteRule ^index\.php$ http://www.google.com [NC,L]
I get sent to google as expected. So obviously I must be doing something wrong with the matching and replacing, but what am I doing wrong?
Thanks in advance.
Edit:
access.log and error.log are error free.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你缺少 + 所以你没有匹配单词,只是一个字符
you are missing the + so you are not matching words, just a single char
试试这个..(删除一个斜线)
try this..(one slash removed)
已修复:必须更改要使用的 HTML URL 样式
然后在
.htaccess
中还必须从 apache 的 httpd.conf 禁用 mod_cache.so,因为如果留下任何缓存,它会干扰重写。希望这可以帮助其他人获得干净的网址。
Fixed: Had to change HTML URL style to be used as such
Then in
.htaccess
Also had to disable mod_cache.so from apache's httpd.conf as it interfere with rewrite if there are any caches left behind. Hope this helps others to get clean urls working.