Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache Mod rewrite在Mozilla中无法正常工作_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

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的注释中?