重写所有的虚拟子域使用htaccess的同一个文件夹有的、重写、文件夹、htaccess

2023-09-02 11:25:29 作者:姑娘、说你了

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

我试图重定向重写

  

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
 
真 0门槛 从解压缩开始的脚本使用教程 适用于pc端模拟器

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