使用 mod_rewrite 的虚拟域和子域
我想创建一项服务,用户可以在我的服务上获取子域或常规域。
这个想法是,除了 www.
之外的所有子域都应该转到 /subdomains.php?user=[sub]&url=[requestet url]
以及除了我自己的域之外的所有域2 个域名应转到 /domain.php?url=$1
我的 2 个域名是: domain1.com
和 domain2.se
我尝试了以下代码:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.domain2\.se$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain2\.se$ [NC]
RewriteRule ^(.*)$ /subdomain.php?user=%2&url=$1 [QSA,L]
#Rewrite
RewriteCond %{HTTP_HOST} !^www\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.domain2\.se$ [NC]
RewriteRule (.*) http://www.domain1.com/domain.php?url=$1 [R=301,L]
</IfModule>
但它不起作用。
I would like to create a service where a user either can get a subdomain or a regular domain on my service.
The idea is that all subdomains except www.
should go to /subdomains.php?user=[sub]&url=[requestet url]
And all domains except my own 2 domains should go to /domain.php?url=$1
My 2 domains are:domain1.com
and domain2.se
I've tried the following code:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.domain2\.se$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain2\.se$ [NC]
RewriteRule ^(.*)$ /subdomain.php?user=%2&url=$1 [QSA,L]
#Rewrite
RewriteCond %{HTTP_HOST} !^www\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.domain2\.se$ [NC]
RewriteRule (.*) http://www.domain1.com/domain.php?url=$1 [R=301,L]
</IfModule>
But it does not seen to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
子域:您如何期望 URL 同时成为
domain1.com
和domain2.se
的子域?尝试例如这种简化:
Sub domains: how do you expect an URL to be both a subdomain of
domain1.com
anddomain2.se
at the same time?Try e.g. this simplification: