关于htaccess和重定向的新手,我希望有人能帮助我。目前,除了一个http urls之外,所有的http urls都正确地重定向到https。
已根据请求更新以下脚本以删除重复项,但问题仍然存在。
示例如下:
http://example.com重定向到https://www.example.com/
http://www.example.com重定向到https://www.example.com/
http://subdomain.example.com重定向到https://subdomain.example.com
麻烦就来了
http://example.com/somepage这只重定向到https://www.example.com/
下面是我的htaccess文件的一个片段。
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^admin$ admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*\.php)$ $1 [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . index.php [L]发布于 2019-02-19 06:25:38
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]这是将所有非https://调用重定向到其安全版本的有效方法。使用它可以将http://example.com/somepage重定向到https://www.example.com/somepage
也许你的301只是被缓存了?请清除缓存,然后重试。我建议您在确认重定向工作正常之前使用R=302标志,然后更新您的.htaccess以使用301。
https://stackoverflow.com/questions/51478303
复制相似问题