我已经寻找这个问题很多天了,尝试了这么多不同的方法,但到目前为止,没有什么有效。我正在使用Question2Answer脚本,我希望将所有的HTTP请求重定向到HTTPS。
我的URL结构设置为:
/123/why-do-birds-sing (requires htaccess file)htaccess文件如下所示:
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:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
</IfModule>这将正确地将http://example.com重定向到https://example.com。但是,如果用户输入这样的地址:www.example.com/users,则将其重定向到https://example.com/index.php?qa-rewrite=users,后者返回一个404错误。
index.php?qa-rewrite=是自动添加的,从htaccess中删除它会把所有事情都搞砸,我认为它应该在那里。
发布于 2014-12-30 07:06:24
这是因为在任何路由规则(没有标志的规则)之前都需要所有重定向规则,因此:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>https://stackoverflow.com/questions/27701011
复制相似问题