真的很快.我希望能够将任何键入 subdomain.mydomain 的人重定向到我的主域上的页面.例如,如果我输入:answers.mydomain,我将被重定向到 mydomain/suberror.
Just a quicky really. I want to be able to redirect anybody who types a subdomain.mydomain to be redirected to a page on my main domain. i.e If I typed: answers.mydomain I would be redirected to mydomain/suberror for instance.
如果可能,我希望这是一个通用规则,因为我认为添加语句以排除我不想被重定向的任何子域比添加语句以包含所有其他子域更容易.顺便说一下,我需要使用 .htaccess 文件.
I would like this to be a universal rule if possible because I thought it would be easier to add statements to exclude any subdomains that I didn't want to be redirected rather than add statements to include every other subdomain. I will need to this using a .htaccess file by the way.
推荐答案尝试将其添加到 .htaccess 文件中的适当位置:
Try adding this to an appropriate place in your .htaccess file:
RewriteEngine On RewriteCond %{HTTP_HOST} ^answers.mydomain$ [NC] RewriteRule ^ mydomain/suberror [L,R]只要请求的主机是 answers.mydomain,就会应用该规则.将正则表达式匹配设置为 ^,any URI 将匹配并且目标将被重定向到 mydomain/suberror
As long as the requested host is answers.mydomain, the rule will be applied. With the regex match set to ^, any URI will match and the target will be redirected to mydomain/suberror
如果您只想将特定的 URI 请求重定向到/suberror,您可以将 ^ 调整为适当的内容.
If you want only specific URI requests to be redirected to /suberror, you can tweak the ^ to something appropriate.
对于所有子域(包括 www.mydomain):
For all subdomains (including www.mydomain):
RewriteEngine On RewriteCond %{HTTP_HOST} ^(.+).mydomain$ [NC] RewriteRule ^ mydomain/suberror [L,R]要排除 www.mydomain,请在 RewriteRule 之前添加以下行:
To exclude www.mydomain, add this line before the RewriteRule:
RewriteCond %{HTTP_HOST} !^www.mydomain$ [NC]更多推荐
将任何子域重定向到主域上的页面
发布评论