我有一个.htaccess
文件,其中包含一些正在做一些事情的重写,它工作正常。它看起来像这样:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Removes .php ending from path
# ---------------
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
# Services & Knowledgebase rewrites
# ---------------
RewriteRule ^services/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)$ /services.php?cat=$1&s=$2 [L]
RewriteRule ^services/([a-zA-Z0-9-/]+)$ /services.php?service=$1 [L]
RewriteRule ^knowledge-base/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)$ /knowledge-base.php?cat=$1&s=$2 [L]
RewriteRule ^knowledge-base/([a-zA-Z0-9-/]+)$ /knowledge-base.php?cat=$1 [L]
</IfModule>
我现在已经向站点添加了 SSL,并且需要为整个站点强制使用 HTTPS。我尝试将以下内容添加到我的.htaccess
:
# Force HTTPS
# ---------------
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
就在RewriteEngine On
声明之后,但是当我尝试时example.com
,网址保持不变example.com
,我得到以下信息:
未找到
在此服务器上找不到请求的 URL /。
如果我去https://example.com
它工作完美。
如何在保留其他重写规则的同时正确强制使用 https?
谢谢你的帮助
麦克风
这是我通常使用的:
RewriteCond %{HTTPS} !=on
RewriteCond %{ENV:HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
从来没有遇到过任何问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句