【发布时间】:2015-12-26 17:26:09
【问题描述】:
我有一个主域https://www.domain.com 或https://domain.com 和一个通配符DNS,如https://domain.com/index.php?name=abcd 强制重定向http://abcd.domain.com,但我还有另一个问题,我的登录页面是https://domain.com/login.php?name=abcd,我想要像强制http://domain.com/login.php?name=abcd 这样的结果但它不能在 HTTP 上重定向。
RewriteEngine On
#match either the www subdomain or no subdomain
RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain\.com)$
#which request index.php
RewriteCond %{REQUEST_URI} ^/index\.php
#and contain a username paramater
RewriteCond %{QUERY_STRING} ^(.*?)(?:^|&)name=([^&]+)(.*?)$
#then rewrite them to name.domain.com without the name parameter
RewriteRule ^ http://%1.domain.com%{REQUEST_URI} [R,L]
#match either the www subdomain or no subdomain
RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain\.com)$
#which was requested without https
RewriteCond %{HTTPS} off
#then redirect to https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
#Capture subdomain
RewriteCond %{HTTP_HOST} ^([^.]+)\.(?:domain\.com)$
#If we're not working on www
RewriteCond %{HTTP_HOST} !^(?:www.domain\.com)$
#If querystring doesn't contain name
RewriteCond %{QUERY_STRING} !^(.*?)(?:^|&)name=([^&]+)(.*?)$
#Add username to querystring
RewriteRule index.php index.php?name=%1 [L,QSA]
这个 htaccess 代码工作正常,但我想在 htaccess 中登录脚本
在聊天中澄清后,这是我需要的:
应将所有 URL 重写为 https,但 login.php 除外,它应保留为 http。如果login.php 以https 出现,则将其重写为http。
【问题讨论】:
-
我阅读了您的 .htaccess,但我不明白您想要实现什么。 “我想在 htaccess 中登录脚本”是什么意思?
-
我想说我想要这个结果domain.com/login.php?name=abcd 我的域是 https 所以它会自动重定向到 https
-
你想要什么输入
/login.php?name=abcd?是您现在拥有index.php的地方,还是除了它或其他东西? -
index.php 也在同一目录中
-
我还是不明白,什么时候你想见
login.php。重定向到login.php的 URL 或条件应该是什么?
标签: php apache .htaccess mod-rewrite redirect