问题描述
我要重定向所有子域名请求重定向到我的主域在我的htaccess的。我需要它也包括某种形式的通配符的重定向。
例如。 washington.mysite.com/~~MD~~aux重定向到mysite.com/washington~~V
但我需要也重定向任何旧的URL的子域mysite.com/washington~~V
例如。 washington.mysite.com/category.aspx?washington-attractions&CatID=17~~MD~~aux重定向到my-site.com/washington~~V
这是我的code到目前为止:
的RewriteCond%{HTTP_HOST} ^华盛顿\ .mysite \ .COM $ [OR]
的RewriteCond%{HTTP_HOST} ^ WWW \ .washington \ .mysite \ .COM $
(。*)重写规则^ $HTTP \:\ / \ / WWW \ .mysite \ .COM \ /华盛顿/ $ 1[R = 301,L]
但它仍然附加旧的URL到新的
例如。 washington.mysite.com/category.aspx?washington-attractions&CatID=17重定向到my-site.com/washington/category.aspx?washington-attractions&CatID=17
基本上我需要重定向washington.mysite.com/*(anything),以my-site.com/washington~~V
任何建议将是多少AP preciated:)
的RewriteCond%{HTTP_HOST} ^(WWW \)?华盛顿\。 [NC]
重写规则^(。*)$ http://www.mysite.com/washington [R = 301,L]
在你的重写规则
你有 / $ 1
相匹配的(。*)
通配符的括号中。这就是为什么你得到的附加旧的URL路径。
我结合你的2 RewriteCondition
的,使得(WWW \。)
搭配可选的?
。
在 [NC]
标志是的标志。
要清除查询字符串,追加?
来重写URL的末尾
的RewriteCond%{HTTP_HOST} ^(WWW \)?华盛顿\。 [NC]
重写规则^(。*)$ http://www.mysite.com/washington? [R = 301,L]
I need to redirect all subdomain requests to be redirected to my primary domain in my htaccess. I need it to also include some sort of wildcard redirect.
e.g. washington.mysite.com/ redirect to mysite.com/washington
but I need to to also redirect any old url on the subdomain to mysite.com/washington
e.g. washington.mysite.com/category.aspx?washington-attractions&CatID=17 redirect to my-site.com/washington
This is my code so far:
RewriteCond %{HTTP_HOST} ^washington\.mysite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.washington\.mysite\.com$
RewriteRule ^(.*)$ "http\:\/\/www\.mysite\.com\/washington/$1" [R=301,L]
However it still appends the old URL to the new one
e.g. washington.mysite.com/category.aspx?washington-attractions&CatID=17 redirects to my-site.com/washington/category.aspx?washington-attractions&CatID=17
Basically I need the redirect washington.mysite.com/*(anything) to my-site.com/washington
Any suggestions would be much appreciated :)
RewriteCond %{HTTP_HOST} ^(www\.)?washington\. [NC]
RewriteRule ^(.*)$ http://www.mysite.com/washington [R=301,L]
In your RewriteRule
you have /$1
which matches the (.*)
wildcard set of parentheses. This is why you're getting the path from the old URLs appended.
I combined your 2 RewriteCondition
's, making the (www\.)
match optional with ?
.
The [NC]
flag is the nocase
flag.
To clear the querystring, append ?
to the end of the rewrite URL
RewriteCond %{HTTP_HOST} ^(www\.)?washington\. [NC]
RewriteRule ^(.*)$ http://www.mysite.com/washington? [R=301,L]
这篇关于我该如何重定向所有子域名请求主域htaccess的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!