目前,我使用以下 htaccess 指令将所有页面重定向到 https:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
但是我有一个页面,http://foo.bar/baz
,需要仅通过 http 访问。使用 htaccess 指令,如何在除此页面之外的所有页面上重定向到 https,用户被迫使用 http?
编辑:我应该提到这是一个 Laravel 4 应用程序,我目前也有以下规则来处理前端 Controller
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
最佳答案
您可以在RewriteRule
中使用负正则表达式模式:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/baz[/?\s] [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /baz[/?\s] [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteRule ^index\.php - [L,NC]
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301,NE]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
关于apache - 如何在 htaccess 中将除一个页面之外的所有页面定向到 HTTPS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39148197/