重写所有的虚拟子域使用htaccess的同一个文件夹 [英] Rewrite all virtual subdomains to same folder using htaccess

查看:229
本文介绍了重写所有的虚拟子域使用htaccess的同一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找互联网试图找到一个解决这个问题,但无法找到一个明确的解决方案。

我试图<打击>重定向重写

  

anything.domain.com/anypage.php?sub=anything&including=get_parameters

  

domain.com/users/anypage.php?sub=anything&including=get_parameters


我已经发现了几个页面可能的解决方案,但他们都略有不同,以我的需求,和编辑它们不断地以失败告终。

任何帮助将是非常美联社preciated。谢谢你。

PS通配符DNS已启用,并且一切都设置正确的Apache。

编辑:

我最终使用了如下因素,似乎工作pretty的好。谢谢你。

 的RewriteCond%{HTTP_HOST}
^(。*)。domain.com的RewriteCond
%{HTTP_HOST}!^ www.domain.com [NC]
重写规则^(。*)$
http://domain.com/users/$1?sub=%1 [P]
 

解决方案

在你的.htaccess文件试试这个规则:

 选项+了FollowSymLinks
RewriteEngine叙述上

#重定向HTTP
的RewriteCond%{HTTP_HOST}!^ WWW \。域\ .COM $ [NC]
的RewriteCond%{HTTP_HOST} ^([^。] +)\。域\ .COM $ [NC]
的RewriteCond%{} SERVER_PORT = 80
重写规则^(。*)$ http://domain.com/users/$1?sub=%1 [R = 301,QSA,L,NE]

#重定向HTTPS
的RewriteCond%{HTTP_HOST}!^ WWW \。域\ .COM $ [NC]
的RewriteCond%{HTTP_HOST} ^([^。] +)\。域\ .COM $ [NC]
的RewriteCond%{} SERVER_PORT = 443
重写规则^(。*)$ https://domain.com/users/$1?sub=%1 [R = 301,QSA,L,NE]

R = 301将与HTTPS状态301重定向
L时可以使最后一条规则
NE是无法逃避查询字符串
QSA将追加现有查询参数

$ 1您REQUEST_URI
 

I have been searching the internet trying to find a solution to this problem but cannot find a definite solution.

I am trying to redirect rewrite

anything.domain.com/anypage.php?sub=anything&including=get_parameters

to

domain.com/users/anypage.php?sub=anything&including=get_parameters


I have found several pages with possible solutions but they all differ slightly to my needs, and editing them continually ends in failure.

Any help would be much appreciated. Thank you.

P.S Wildcard DNS are enabled and everything is set up correctly in apache.

Edit:

I ended up using the folowing, it seems to work pretty well. Thanks.

RewriteCond %{HTTP_HOST}
^(.*).domain.com RewriteCond
%{HTTP_HOST} !^www.domain.com [NC]
RewriteRule ^(.*)$
http://domain.com/users/$1?sub=%1 [P]

解决方案

Try this rule in your .htaccess file:

Options +FollowSymLinks
RewriteEngine on

# redirect for http
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*)$ http://domain.com/users/$1?sub=%1 [R=301,QSA,L,NE]

# redirect for https
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(.*)$ https://domain.com/users/$1?sub=%1 [R=301,QSA,L,NE]

R=301 will redirect with https status 301
L will make last rule
NE is for no escaping query string
QSA will append your existing query parameters

$1 is your REQUEST_URI

这篇关于重写所有的虚拟子域使用htaccess的同一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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