htaccess虚拟子域和参数

时间:2011-12-16 09:35:49

标签: .htaccess

我有一个用于创建工作正常的虚拟子域的htaccess

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(css|gif|ico|jpg|js|png|swf|txt|JPG)$
RewriteRule ^(.*)$  virtialsubdomain.php?subdomain=%1 [L]

通过以上我可以看到例如virtual1.domain.com,virtual2.domain.com等

我想扩展htaccess,所以我可以传递2个参数进行分页和排序

示例

virtual1.domain.com/p/3 show page 3 
virtual1.domain.com/sort/id,asc show results sort by id asc
virtual1.domain.com/sort/id,asc/p/3 the combination of 2 above

对于www.domain.com中的其他页面,我有实现该目的的规则

RewriteRule category/([^.]+)/sort/([^.]+)/p/([0-9]+)?$ /file.php?id=$1&sort=$2&p=$3 [L,NC,QSA]
RewriteRule category/([^.]+)/sort/([^.]+)?$ /file.php?id=$1&sort=$2 [L,NC,QSA]
RewriteRule category/([^.]+)/p/([0-9]+)?$ /file.php?id=$1&p=$2 [L,NC,QSA]

但我真的不知道如何在虚拟子域名时编写规则

任何帮助表示赞赏

1 个答案:

答案 0 :(得分:0)

我总是先把事情分开。将所有子域请求映射到子域文件夹,如下所示:

RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^subdomains/
RewriteRule ^(.*)$  /subdomains/$1 [L]

然后在/ subdomains /中创建一个单独的htaccess来执行分页和排序规则。

RewriteBase /subdomains
RewriteRule ^p/([0-9]+)$  index.php?page=$1 [L,QSA]
RewriteRule ^sort/([^/]+)(/p/([0-9]+))?$  index.php?sort=$1&page=$3 [L,QSA]
相关问题