开发者

htaccess mod-rewrite to subdomain

I'm using the following to redirect wildcard sub domains to corresponding folders:

RewriteCond %{REQUEST_URI} !^/users/ [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteCond %1 !=www [NC]
RewriteRule ^(.*)$ /users/%1/$1/? [L]

I would like to add a rewrite rule that redirects anyone that accesses the direct /users/ path back to the sub-domain version like this:

www.domain.com/users/username/../../ => username.domain.com开发者_StackOverflow/../../

Thank you in advance!


Something like this:

RewriteEngine On

RewriteCond %{http_host} ^domain.com [nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^users/([a-z0-9\-_\.]+)/?(.*)$ http://$1.domain.com/$2 [QSA,NC,R,L]

Do you have other rules than the one listed on the question? if yes, put these before the other one.

eg:

http://www.domain.com/users/abc?q=test => http://abc.domain.com/?q=test
http://www.domain.com/users/abc/sub1/sub2 => http://abc.domain.com/sub1/sub2
http://www.domain.com/users/abc/sub1/?q=test => http://abc.domain.com/sub1/?q=test
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜