1

我有一个通配符子域 *.domain.com 分配给 public_html/。

我想这样做:

例如,/folder1/index.php 基于状态名称(?state=statename)。

对于 /folder1/folder2/index.php,它将基于唯一名称(?name=uniquename)。

所以, www.domain.com/folder1/index.php?state=statename 将是 statename.domain.com

和 www.domain.com/folder1/folder2/index.php?name=uniquename 将是 uniquename.domain.com

这是我的代码

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+folder1/index\.php\?state=([^\s&]+) [NC]
RewriteRule ^ http://%1.domain.com/? [R=301,L]

RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+folder1/folder2/index\.php\?name=([^\s&]+) [NC]
RewriteRule ^ http://%1.domain.com/? [R=301,L]

问题是它重定向回 public_html 目录。代码有问题吗?

旧代码

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^$ /index [L]

RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).domain.com$ [NC]
RewriteRule ^(index)/?$ /$1.php?name=%2 [L,NC,QSA]

代码说明:每当用户输入uniquename.domain.com,它会自动转到www.domain.com/index.php?name=uniquename,并且uniquename.domain.comin url bar不会改变。

新问题的不同之处在于状态目录不同,域为 state1.uniquename.domain.com。url 栏中的“state1.uniquename.domain.com”也不应该改变。

4

1 回答 1

1

根据您的评论。确保DOCUMENT_ROOT, www.domain.com,是state1.domain.com_state2.domain.compublic_html

试试这个代码:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+folder1/index\.php\?state=([^\s&]+) [NC]
RewriteRule ^ http://%1.domain.com/? [R=301,L]

RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+folder1/folder2/index\.php\?name=([^\s&]+) [NC]
RewriteRule ^ http://%1.domain.com/? [R=301,L]

RewriteCond %{REQUEST_URI} !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.([^.]+)\.domain\.com$ [NC]
RewriteRule ^ /state/%1/client/index.php?name=%2&page=%{REQUEST_URI} [L,NC]
于 2013-10-08T17:11:43.290 回答