我如何结合这两个 .htaccess 规则?
How do I combine these two .htaccess rules?
我想结合这两个规则,但不确定如何
RewriteRule ^([^\.]+)$ .html [L]
RewriteRule ^(.*)$ http://www.example.com/ [L,R=301]
当我同时放置两者时,出现错误“太多重定向”
我的目标是将它们结合起来,
第一条规则是删除文件扩展名(例如 html)
第二条规则是:让每个 URL 去 https://www.example.com, rather than https://example.com
根据您现在提供的附加信息,我建议采用这种方法:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,END]
RewriteRule ^/?(.+)\.html$ / [R=301,END]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [END]
一般来说,开始使用 R=302
临时 重定向并仅将其更改为 R=301
永久重定向是一个很好的选择 一切正常后重定向。这可以防止讨厌的缓存问题...
我想结合这两个规则,但不确定如何
RewriteRule ^([^\.]+)$ .html [L]
RewriteRule ^(.*)$ http://www.example.com/ [L,R=301]
当我同时放置两者时,出现错误“太多重定向”
我的目标是将它们结合起来,
第一条规则是删除文件扩展名(例如 html)
第二条规则是:让每个 URL 去 https://www.example.com, rather than https://example.com
根据您现在提供的附加信息,我建议采用这种方法:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,END]
RewriteRule ^/?(.+)\.html$ / [R=301,END]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [END]
一般来说,开始使用 R=302
临时 重定向并仅将其更改为 R=301
永久重定向是一个很好的选择 一切正常后重定向。这可以防止讨厌的缓存问题...