【发布时间】:2017-02-20 19:15:46
【问题描述】:
目前我们在.htaccess中有这个规则
RewriteEngine on <br>
RewriteCond %{REQUEST_URI} !^/site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site/$1
RewriteRule ^(/)?$ site/index [L]
如果页面未找到,我们将重定向到子文件夹调用站点的任何访问。发生这种情况时,网址不会将站点显示为子文件夹。
例如,如果我们有
/rootFolder/site/temp.html 这将在 url 中显示为
http://www.domain.com/temp.html
这工作正常,但现在我们需要在用户访问站点时添加 https 重定向。
这是我想出的新规则
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ https://%{HTTP_HOST}/site/$1
RewriteRule ^(/)?$ https://%{HTTP_HOST}/site/index [L]
但是这个问题现在是 url 将显示站点子文件夹 https://www.domain.com/site/temp.html
如果用户这样做,我该如何实现
http://www.domain.com/temp.html 它会在站点子文件夹中找到 temp.html 并重定向到 https 并且 url 只会显示
https://www.domain.com/temp.html
谢谢
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite httpd.conf