我需要为我的网站清理URL。结构是这样的:
example.com/home
在主文件夹中,我有:
index.php
ambiente.php
.htaccess
这是我的.htaccess
代码:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+ambiente\.php\?ambiente=([^\s&]+) [NC]
RewriteRule ^ ambiente/%1? [R=301,L]
RewriteRule ^ambiente/([^/]+)/?$ ambiente.php?ambiente=$1 [L,QSA]
我希望文件这样做:
example.com/home/ambiente.php?ambiente=living
example.com/home/ambiente/living
问题在于URL不会自动重写。
如果单击ambiente.php?ambiente=living
索引文件中的链接,则会在地址栏中找到example.com/home/ambiente.php?ambiente=living
。
如果我在地址栏中输入:http://example.com/home/ambiente/living
,它将正常工作!
我该如何解决?
您的Rewritecondition匹配,/ambiente.php?ambiente=foobar
但与原始uri不匹配。/home/ambiente.php?ambiente=foobar
用以下内容替换您的第一个rewriteRule
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+home/ambiente\.php\?ambiente=([^\s&]+) [NC]
RewriteRule ^ /home/ambiente/%1? [R=301,L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句