【发布时间】:2014-12-30 07:02:32
【问题描述】:
我已经搜索这个问题很多天并尝试了很多不同的方法,但到目前为止没有任何效果。我正在使用 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 中删除它会完全搞砸一切,我认为它应该在那里。
【问题讨论】:
标签: apache .htaccess mod-rewrite redirect question2answer