我想将所有非www页面重定向到https://,但是只有主页可以按预期进行。也就是说,http://kraftgiftbox.com将重定向到https://www.kraftgiftbox.com/,这是可以的! 但是,任何子级别的页面都不会像https://kraftgiftbox.com/odd-shaped-boxes.html那样重定向到www版本。 我有一个.htaccess文件,如下所示:
RewriteOptions inherit
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://kraftgiftbox.com/$1 [R,L]
ErrorDocument 404 /404.shtml
RewriteCond %{HTTP_HOST} ^kraftgiftbox\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "https\:\/\/www\.kraftgiftbox\.com\/" [R=301,L]
有人可以帮助我更正代码吗?谢谢!
答案 0 :(得分:0)
最后一行规则导致此问题,因为您仅通过此RewriteRule ^/?$
捕获根请求,才能实现所需的尝试:
ErrorDocument 404 /404.shtml
RewriteOptions inherit
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?kraftgiftbox\.com$ [NC,OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.kraftgiftbox.com/$1 [R=301,L]
以上规则将同时执行,同时强制https
和www
。
注意,清除浏览器缓存,然后进行测试。