.htaccess 将整个Q2A网站重定向到HTTPS

.htaccess 将整个Q2A网站重定向到HTTPS,.htaccess,redirect,mod-rewrite,https,question2answer,.htaccess,Redirect,Mod Rewrite,Https,Question2answer,我一直在使用,我正在尝试使用.htaccess将整个网站重定向到https。问题是,文件中正在进行重写,这会导致混乱 DirectoryIndex index.php <IfModule mod_rewrite.c> RewriteEngine On #RewriteBase / RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ RewriteRule . %1/%2 [R=301,L] RewriteCond %{REQUEST_FILE

我一直在使用,我正在尝试使用.htaccess将整个网站重定向到https。问题是,文件中正在进行重写,这会导致混乱

 DirectoryIndex index.php
 <IfModule mod_rewrite.c>
 RewriteEngine On
 #RewriteBase /
 RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
 RewriteRule . %1/%2 [R=301,L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]

 RewriteCond %{HTTP_HOST} !^www\.
 RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

 </IfModule>
它确实管用,但它把重写工作搞砸了

 RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
更新

有了这些额外的代码,我得到的是:

https://www.example.com/index.php?qa-rewrite=123/this-is-a-title
应该是:

https://www.example.com/123/this-is-a-title

htaccess中重写规则的顺序非常重要,因为规则是从上到下执行的

请尝试以下代码:

 DirectoryIndex index.php
 <IfModule mod_rewrite.c>
 RewriteEngine On
 #RewriteBase /

 RewriteCond %{HTTP_HOST} !^www\. [NC]
 RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

 RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
 RewriteRule . %1/%2 [R=301,L]

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^.*$ index.php?qa-rewrite=$0 [L,QSA]

 </IfModule>
DirectoryIndex.php
重新启动发动机
#重写基/
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州]
重写规则^https://www.%{HTTP_HOST}%{REQUEST_URI}[R=301,L,NE]
RewriteCond%{REQUEST_URI}^(.*)/(.*)$
重写规则%1/%2[R=301,L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
RewriteRule^.*$index.php?qa rewrite=$0[L,QSA]

看起来比我的好多了,希望这对OP有用。+1:)
 DirectoryIndex index.php
 <IfModule mod_rewrite.c>
 RewriteEngine On
 #RewriteBase /

 RewriteCond %{HTTP_HOST} !^www\. [NC]
 RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

 RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
 RewriteRule . %1/%2 [R=301,L]

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^.*$ index.php?qa-rewrite=$0 [L,QSA]

 </IfModule>