URL取决于重定向htaccess

时间:2014-02-26 12:34:04

标签: apache .htaccess mod-rewrite

我正在尝试重定向,具体取决于用户输入的网址,如果用户输入ins-dev.com重定向到确切的网址,如果输入www.ins-dev.com删除www并重定向到ins-dev .com(http://)。 但是如果用户输入ins-staging.com以重定向https://ins-staging.com,则在www的情况下将其删除并执行相同的重定向。 最后,如果用户输入trac-staging.com,我想将其重定向到https://ins-staging.com,与上面的www逻辑相同。 这就是我现在所拥有的:

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [OR,NC]

RewriteCond %{REQUEST_URI} ^ins-dev.com$
RewriteRule ^$ http://ins-dev.com [L,R=301]


RewriteCond %{HTTP_HOST} ^trac-staging\.com$ [NC]
RewriteRule ^ https://ins-staging.com%{REQUEST_URI} [L,R=301]

现在与这么长时间的战斗,在任何形式的帮助下提前感谢。 如果用户输入例如:ins-staging.com/video.php

,则最后%{REQUEST_URI}有用

1 个答案:

答案 0 :(得分:0)

您可以使用:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.((?:trac-staging|ins-staging)\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]