【发布时间】:2018-04-23 15:48:25
【问题描述】:
我有一个.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,同时保留我的其他重写规则?
感谢您的帮助
迈克
【问题讨论】:
-
嗨 - 我不认为它是重复的。那篇文章是关于从 https 强制 to http,并且不包含任何关于使用额外重写的内容。
标签: apache .htaccess mod-rewrite