简体   繁体   English

重定向除一个子域外的所有内容

[英]Redirect everything, except one subdomain

Everything has to redirect to www.domain.com. 一切都必须重定向到www.domain.com。 except for test.domain.com. test.domain.com除外。 Which will host a new version of the site for testing. 哪个将托管新版本的网站进行测试。 both of the domains need to look within their web directory. 这两个域都需要在其Web目录中查看。

I've searched stack overflow but none of the similar questions seem to provide a working solution for me. 我搜索了堆栈溢出,但没有类似的问题似乎为我提供了一个有效的解决方案。 Probably because I don't understand htacces / regex that well yet. 可能是因为我还不了解htacces / regex。

This is the current content of my .htacces file. 这是我的.htacces文件的当前内容。

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]

Try this for your second line (where test is your subdomain): 试试这个你的第二行(测试是你的子域):

RewriteCond %{HTTP_HOST} !^(www|test)\.

The ! 的! negates the match. 否定比赛。

The brackets are a regex group. 括号是正则表达式组。

The pipe symbol is an or. 管道符号是或。

What this should say is "match me all subdomains except www. & test." 这应该说的是“匹配我除了www。&test之外的所有子域名。”

Regex101 link here which might help explain further and gives my test data: Regex101链接在这里可能有助于进一步解释并提供我的测试数据:

https://regex101.com/r/5udsER/1/ https://regex101.com/r/5udsER/1/

Disclaimer : 免责声明

I wrote this afk so this is lacking an end-to-end test but should work. 我写这个afk所以这是缺乏端到端的测试,但应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM