重写子域和文件夹的规则

时间:2011-01-26 09:35:02

标签: apache mod-rewrite subdomain

我需要为Apache编写一个重写规则,以便与子域一起使用。规则应基于:

subdomain.domain.com => /home/domain/docs/some_folder/file.php?subdomain=subdomain
subdomain.domain.com/edit => /home/domain/docs/some_other_folder/file.php
subdomain.domain.com/dashboard/display/id => /home/domain/docs/some_other_folder2/file.php?param1=display&param2=id

我也在网站上使用AJAX调用,这些调用并不容易,因为我从搜索互联网时理解。所以一些暗示也确实有帮助。

非常感谢你的帮助! 提前谢谢。

1 个答案:

答案 0 :(得分:0)

我要试试这个

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^subdomain.domain.com$
RewriteRule .* - [L]

RewriteCond %{HTTP_HOST} (.*)
RewriteRule ^$  /home/docs/some_folder/file.php?subdomain=%1 [L,QSA]
RewriteRule ^edit$  /home/docs/some_other_folder/file.php [L]
RewriteRule ^dashboard/(\w+)/(\w+) /home/docs/some_other_folder2/file.php?param1=$1&param2=$2 [QSA,L]