htaccess的mod-rewrite到子域名 [英] htaccess mod-rewrite to subdomain

查看:108
本文介绍了htaccess的mod-rewrite到子域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的重定向通配符子域,以相应的文件夹:

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/../../

感谢你在前进!

推荐答案

事情是这样的:

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.

例如:

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

这篇关于htaccess的mod-rewrite到子域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆