【发布时间】:2017-08-22 14:15:27
【问题描述】:
我正在尝试将一个 url 重定向到 https 并将所有其他 url 重定向到 http 例如:如果我想访问 example.com 的登录页面,它应该重定向到 https://example.com/login 如果我想访问登录以外的任何页面,它们应该被重定向到http://example.com/any-other-page。 当前的 .htaccess 代码:
RewriteEngine on
RewriteCond %{HTTPS} =on
RewriteRule !^(login) http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
DirectoryIndex index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
这工作正常。登录以外的所有 url 都重定向到 http。 但是如果我添加以下代码来重定向登录页面,它会被重定向到 index.php
RewriteCond %{HTTPS} !=on
RewriteRule (login) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
我想要的只是登录页面应该重定向到 https。但这并没有发生。
提前致谢。
【问题讨论】:
标签: apache .htaccess url-redirection