问题描述
我想我所有的文件夹(使用通配符)重定向到其子域。例如:
现在无需编写规则他们每个人,有没有办法把它们全部重定向到各自的子域名?
我想:
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST}!^ WWW \ .mywebsite \ .COM $
的RewriteCond%{HTTP_HOST} ^(\ W +)\。mywebsite \ .COM $
重写规则^(。*)$ / 1%/ $ 1 [QSA]
但它给了我一个内部错误500
您需要保持规则的循环,使用条件,首先检查 /%1 / $ 1
确实存在,或的URI尚未与%1
所以:
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST}!^ WWW \ .mywebsite \ .COM $
的RewriteCond%{HTTP_HOST} ^(\ W +)\。mywebsite \ .COM $
的RewriteCond%{DOCUMENT_ROOT} /%1%{REQUEST_URI} -f [OR]
的RewriteCond%{DOCUMENT_ROOT} /%1%{REQUEST_URI} -d
重写规则^(。*)$ / 1%/ $ 1 [QSA]
或者
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST}!^ WWW \ .mywebsite \ .COM $
的RewriteCond%{HTTP_HOST} ^(\ W +)\。mywebsite \ .COM $
的RewriteCond%{REQUEST_URI}:%1 ^ /([^ /] +)/([^:] *):!\ 1
重写规则^(。*)$ / 1%/ $ 1 [QSA]
在 ^ /([^ /] +)/([^:] *):!\ 1
EX pression团体第一次在URI文件夹,并与反向引用它\ 1
。如果这些都是平等的,那么在URI的第一个文件夹是%1
这是backreferenced到previous比赛(\ w +)
。
I'm trying to redirect all my folders (using a wildcard) to their subdomain. For example:
Now without writing a rule for each one of them, is there a way to redirect them all to their respective subdomain?
I tried:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.mywebsite\.com$
RewriteRule ^(.*)$ /%1/$1 [QSA]
But it gives me an internal error 500
You need to keep the rules from looping, use a condition to first check if the /%1/$1
actually exists, or that the URI doesn't already start with %1
So:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.mywebsite\.com$
RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI} -d
RewriteRule ^(.*)$ /%1/$1 [QSA]
Or:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.mywebsite\.com$
RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
RewriteRule ^(.*)$ /%1/$1 [QSA]
The !^/([^/]+)/([^:]*):\1
expression groups the first folder in the URI, and backreferences it with \1
. If those are equal, then the first folder in the URI is %1
which is backreferenced to the previous match (\w+)
.
这篇关于如何写一个htaccess文件夹通配符子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!