繁体   English   中英

使用 .htaccess 捕获域名

[英]Catching the domain name with .htaccess

我对使用 .htaccess 和 modrewrite 还很陌生。

我在 php 中有一个多租户网站,每个租户都可以在将其指向我的服务器 ip 后将他购买的域名保存在应用程序数据库中。

现在我正在尝试通过 .htaccess 编写一个重写规则,以便当用户在地址栏中键入他的域(例如 www.example.com)时,.htaccess 会解析主机名并将其作为参数传递给索引页,因此对 www.example.com 的每个请求都会变成这样: /index.php?domain=www.example.com 。

甚至 www.example.com/user 变成 /index.php?domain=www.example.com&url=user

我怎样才能用 .htaccess 做到这一点?

感谢您的帮助 !

您可以在站点根目录 .htaccess 中使用此规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} !domain= [NC]
RewriteRule ^(?:index\.php)?$ index.php?domain=%{HTTP_HOST} [L,QSA,NC]

RewriteCond %{QUERY_STRING} !domain= [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php?domain=%{HTTP_HOST}&url=%{REQUEST_URI} [L,QSA]

暂无
暂无

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

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