【发布时间】:2015-01-01 09:10:43
【问题描述】:
我有一个基于注册用户名的动态子域的站点,这些用户名使用 php 解析,因此我的 htaccess 可以正常工作。 下面是一些关于如何从 $_SERVER 进行重定向的示例
thecspace.com/blogs
["QUERY_STRING"] => string(21) "template=www&q=blogs/"
http://www.thecspace.com/blogs/test-pp-blog-2904
["QUERY_STRING"] => string(38) "template=www&q=blogs/test-pp-blog-2904"
http://danvlad.thecspace.com/blogs/test-pp-blog-2904
["QUERY_STRING"] => string(47) "template=danvlad&q=blogs/test-pp-blog-2904"
当前的 HT 访问权限
RewriteCond %{HTTP_HOST} ^thecspace\.com$ [NC]
RewriteRule ^(.*)$ http://www.thecspace.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)?\.thecspace\.com
RewriteRule ^$ index.php?template=%2 [L,QSA]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)?\.thecspace\.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?template=%2&q=$1 [L,QSA]
现在是困难的部分。我想允许自定义域使用相同的规则。假设 devdemogroup 有域 devdemogroup.com。一旦他们将 DNS 更改为指向 domain.com,我希望能够允许该域使用 domain.com 中的当前代码
因此,理论上对 www.danvlad.com 的请求将是一个 this 查询字符串
["QUERY_STRING"] => string(47) "template=danvlad"
和 www.danvlad.com/blogs/
["QUERY_STRING"] => string(47) "template=danvlad&q=blogs"
我试过了,但是不行
RewriteCond %{HTTP_HOST} !^www\.thecspace\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.thecspace\.com$ [NC]
RewriteRule ^$ /index.php?template=%1 [L]
RewriteCond %{HTTP_HOST} !^www\.thecspace\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.thecspace\.com$ [NC]
RewriteRule ^$ /index.php?template=%1 [L]
RewriteCond %{HTTP_HOST} !^www\.thecspace\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.com$ [NC]
RewriteRule ^$ /index.php?template=%1 [L]
RewriteRule ^(.*)$ /index.php?template=%1?q=$1 [L,QSA]
有人可以帮忙吗? 谢谢
【问题讨论】:
标签: regex apache .htaccess mod-rewrite dns