我有一个网站要工作,并试图通过htaccess重定向几天。我搜索了网络,找到了好的作品,特别是在这个网站上,但是我已经尝试了几乎所有的可能性,我无法实现我想做的事情。
我的需要是将所有站点重定向到非www http,包括https,只有一个文件除外。比方说重定向://www.example.com/.../....php?a=...
://www.example.com/.../....php?a=... https
://example.com/.../....php?a=... https
至
://example.com/.../....php?a=... http
但是,只有一个特定的文件
://www.example.com/.../theSpecificFile.php?a=... http
://www.example.com/.../theSpecificFile.php?a=... https
://example.com/.../theSpecificFile.php?a=... http
应该重定向到
://example.com/.../theSpecificFile.php?a=... https
为此,我编写了许多htaccess文件,但在每种情况下,我都无法满足自己的需要。例如在最后一次htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
ErrorDocument 404 http://example.com/404.php
#force https for certain pages
RewriteCond %{HTTPS} !=on
RewriteRule ^(theSpecificFile\.php)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
#redirect www.example.com to example.com (or any other subdomain)
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
通过这个htaccess文件,
当我尝试https ://www时,我得到了不安全或不受信任的连接(我正在从另一种语言进行翻译,希望这是真正的翻译)与ssl_error_bad_cert_domain
当我试图访问theSpecificFile.php时,定义"infine “时会出错(同样,我希望这可能是一个真正的翻译)。
这对我来说真的很令人沮丧,所以,任何帮助都将是非常感谢的。
提前感谢
发布于 2014-11-27 11:19:10
看,这里您将theSpecificFile.php
重定向到它的https版本,但是第二个重定向规则触发并将浏览器重定向回http,然后第一个规则重定向回https.这就是你得到无限循环的原因。
ssl_error_bad_cert_domain意味着证书不是该域的证书,因此您可能需要检查是否使用了正确的证书。
发布于 2014-11-27 11:25:14
请尝试:
RewriteCond %{HTTPS} on
RewriteConf %{REQUEST_URI} !=/theSpecificFile.php
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
发布于 2014-11-27 11:43:12
你可以用它:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{REQUEST_URI} !/theSpecificFile\.php [NC]
RewriteRule ^ http://example.com/%{REQUEST_URI} [L,R=302]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} /theSpecificFile\.php [NC]
RewriteRule ^ https://example.com/%{REQUEST_URI} [L,R=302]
当一切正常时,将R=302,L改为R=301,L
https://stackoverflow.com/questions/27177384
复制相似问题