使用 mod_rewrite 的虚拟域和子域

发布于 2024-12-25 08:15:56 字数 961 浏览 3 评论 0原文

我想创建一项服务,用户可以在我的服务上获取子域或常规域。

这个想法是,除了 www. 之外的所有子域都应该转到 /subdomains.php?user=[sub]&url=[requestet url]

以及除了我自己的域之外的所有域2 个域名应转到 /domain.php?url=$1

我的 2 个域名是: domain1.comdomain2.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长梦不多时 2025-01-01 08:15:56

子域:您如何期望 URL 同时成为 domain1.comdomain2.se 的子域?

尝试例如这种简化:

RewriteCond %{HTTP_HOST} !^www\.(domain1\.com|domain2\.se)$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.(domain1\.com|domain2\.se)$ [NC]

Sub domains: how do you expect an URL to be both a subdomain of domain1.com and domain2.se at the same time?

Try e.g. this simplification:

RewriteCond %{HTTP_HOST} !^www\.(domain1\.com|domain2\.se)$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.(domain1\.com|domain2\.se)$ [NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文