Apache 如何将htaccess中除一个页面外的所有页面定向到HTTPS?
目前,我正在使用以下htaccess指令将所有页面重定向到https:Apache 如何将htaccess中除一个页面外的所有页面定向到HTTPS?,apache,.htaccess,redirect,mod-rewrite,laravel-4,Apache,.htaccess,Redirect,Mod Rewrite,Laravel 4,目前,我正在使用以下htaccess指令将所有页面重定向到https: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 但我有一页,http://foo.bar/baz只需通过http访问。使用htaccess指令,我如何在所有页面上重定向到https,除了这个页面,在这个页面上,用户被强制使用http 编辑:我应该提到这是一个Laravel4
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
但我有一页,http://foo.bar/baz
只需通过http访问。使用htaccess指令,我如何在所有页面上重定向到https,除了这个页面,在这个页面上,用户被强制使用http
编辑:我应该提到这是一个Laravel4应用程序,我目前也有以下规则来处理前端控制器
# 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]
当您需要一个或多个异常时,负前瞻尤其适用于这些情况:
RewriteRule ^(?!baz)(.*) https://%{HTTP_HOST}/$1 [R,L]
这基本上是说,重定向除baz以外的所有内容
旁注:记住“.htaccess”不是Apache的某种重写库,如果您可以访问virtualhost中的配置,请确保在其中添加这些重写。htaccess增加了开销和复杂性 对不起,你能解释一下这里的逻辑吗?嗯,这似乎对我不起作用/baz仍然重定向https。我添加了一些关于应用程序是laravel的信息以及它附带的规则。你能看一下然后给我回电话吗?啊,我明白了,所以你有其他规定。我已经为你提供了完整的.htaccess,这应该对你有用。请完全清除浏览器缓存。好的,这允许我通过http查看baz,但不会强制在baz上使用http。我能强迫你吗?