我有一个超级基本的重定向请求,我想完成,但是每次尝试都将其弄乱,到目前为止,最好的结果是双重www.www重定向(http://www.www.domain.tld /)
我的.htaccess有“两个”规则,我想检查并完成。
1st:将所有不存在的文件重定向到根文件夹
第二名:添加www。如果网域要求为非www
# If requested resource exists as a file or directory go to it
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.*) - [L]
# Else rewrite requests for non-existent resources to /index.php
RewriteRule (.*) http://www.%{HTTP_HOST}/? [L]
#Rewrite for non www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/? [R=301,L]
我已经更改了第一个规则集,但从未解决过
1号
# If requested resource exists as a file or directory go to it
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.*) - [L]
# Else rewrite requests for non-existent resources to /index.php
RewriteRule (.*) http://%{HTTP_HOST}/? [L]
以redirectloop结尾
2号
# If requested resource exists as a file or directory go to it
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.*) - [L]
# Else rewrite requests for non-existent resources to /index.php
RewriteRule (.*) /? [L]
结束,甚至没有给出任何规则..因此,错误404站点的URL保持不变http://www.domain.tld/123456789.html
我在哪里走错路了?
http://
静默重写时不能使用,否则mod_rewrite
会将其转换为外部重定向。有这样的规则:
DirectoryIndex index.php
RewriteEngine On
#Rewrite for non www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# If requested resource is not a file or directory then redirect to /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L,R=302]
在测试之前,请确保清除浏览器缓存。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句