【发布时间】:2023-04-04 18:29:01
【问题描述】:
我正在尝试将 一个 特定的 url,比如说 /admin,从我的域重定向到 http,而其他的都应该重定向到 https。示例:
Works:
http://example.com -> https://example.com
http://example.com/with-url -> https://example.com/with-url
https://example.com/admin -> http://example.com/admin
Does not work:
What I get (redirects from https to http, if under /admin):
https://example.com/admin/anything-below-here -> http://example.com/admin/anything-below-here
What I want (to stay on https):
https://example.com/admin/anything-below-here -> https://example.com/admin/anything-below-here
这是我目前得到的:
RewriteEngine On
# force https:// for all except /admin
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/admin [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force http:// for /admin URLs
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /admin [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# all the others
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
谁能告诉我我在这里缺少什么?非常感谢!
【问题讨论】:
标签: apache .htaccess mod-rewrite