我已经搜索了这个问题很多天,并尝试了很多不同的方法,但到目前为止没有任何效果。我正在使用 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 错误的地址。
自动添加并从 htaccess中index.php?qa-rewrite=
删除它完全搞砸了一切,我认为它应该在那里。