【发布时间】:2016-08-13 09:16:09
【问题描述】:
我正在尝试强制我的根域的子文件夹 (/bbb/) 始终显示为 https。我的.htaccess 文件也负责页面的扩展。
我已将.htaccess 文件放在我的/bbb/ 文件夹中,但是当我尝试强制连接到 https 时,我得到“重定向过多”,没有它一切正常。
我的代码有什么问题?
Options +FollowSymLinks -MultiViews
Options +Indexes
AcceptPathInfo Off
RewriteEngine on
RewriteBase /
ErrorDocument 404 https://example.co.uk/404page/404.html
#Force from http to https
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} !^bbb.example.co.uk/$
RewriteRule ^(.*)$ https://bbb.example.co.uk/$1 [R=301]
#take off index.html
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
## hide .html extension
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
【问题讨论】:
-
HTTP_HOST 只包含主机名。你的
bbb.example.co.uk/永远不会匹配,因为/不是主机名的有效部分。
标签: apache .htaccess redirect mod-rewrite