Apache Mod rewrite在Mozilla中无法正常工作
我正在重写所有Apache Mod rewrite在Mozilla中无法正常工作,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我正在重写所有http://和http://www在我的网站上转到https://www 除Mozilla Firefox外,所有浏览器都运行良好。当我尝试使用http://example.com,它重定向到:https://www.example.com/https:/example.com/ 我的.htaccess: RewriteCond %{HTTP_HOST} ^(example\.com)$ [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{R
http://
和http://www
在我的网站上转到https://www
除Mozilla Firefox外,所有浏览器都运行良好。当我尝试使用http://example.com
,它重定向到:https://www.example.com/https:/example.com/
我的.htaccess:
RewriteCond %{HTTP_HOST} ^(example\.com)$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule ^([^/]*)$ hosted_form.php/?username=%1&hash=$1 [R,L]
请告诉我如何解决这个问题?首先,您的前两条规则可以合并为一条:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com$%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteRule ^([^/]+)/?$ hosted_form.php/?username=%1&hash=$1 [R,L,QSA]
完成后,您需要清除Firefox上的浏览器缓存,因为“重写”在所有浏览器上的行为都应该相同。尽管很有趣,但这根本不是一个答案。它应该是一个注释。你有没有试过把这么大的代码放在SO的注释中?