我试图使所有版本的主页网址301到相同的地方,没有301。
很难显示问题,因为我没有足够的代表点来发布图像或在图表中显示http响应代码(链接太多!)
但是,在301s转到主页URL http://example.com之前,使用下面的https://www.example.com/代码首先转到http://www.example.com/
我在使用apache,并且我一直在使用.htaccess来尝试解决这个问题。
我也尝试过以下方法,但它只适用于文件路径。重定向301 /oldfile.htm /newfile.htm
# Redirect HTTPS to HTTP
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example/$1 [L,R=301]我也尝试过以下方法,但它只适用于文件路径。
Redirect 301 /oldfile.htm /newfile.htm有没有办法不用301链就能让https://www.example.com/转到http://example.com?
谢谢,迈克。
发布于 2019-10-15 22:35:25
您可以使用单个规则将https URL重定向到http和非www版本。这会将您的所有https urls重定向到http,而不会创建多个重定向链。
将您的htaccess规则替换为:
# Redirect HTTPS to HTTP and non-www
RewriteCond %{HTTP:X-Forwarded-Proto} =https [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [L,R=301]请确保清除浏览器缓存或使用其他web浏览器来测试此规则。
https://stackoverflow.com/questions/58394001
复制相似问题