子域和 restful 结构的 apache mod_rewrite 规则

子域和 restful 结构的 apache mod_rewrite 规则

我正在尝试设置几条重写规则,允许 restful url 结构存在,但仅限于某个子域。多个子域已经指向共享代码库。为了使用 PHP smarty,我还准备了一个现有的重写,它已经捕获了所有内容。最后一步是,所有子域(包括 restful 子域)都需要重定向到那里。

最后,为了方便起见,如果可能的话,我想尝试将子域放入查询字符串变量中,以避免以后尝试以编程方式提取它。

我是 mod_rewrite 的新手,在让所有这些协同工作方面遇到了麻烦... 这是我迄今为止的混合尝试,但并不能完全协同工作。

# copy subdomain to variable.  
# ideally though, dev.subdomain.domain.com would only copy "subdomain", not "dev.subdomain". 
# this should work for all subdomain, and keep going.
RewriteCond %{HTTP_HOST} (.+).domain.com [NC]
RewriteRule / /$1?subdomain=%1 [QSA]

# restful api, only for restful.domain.com. how to apply to all rules?
RewriteCond %{HTTP_HOST} restful.domain.com
RewriteRule ^/user/([^/]+)/ /calendar/?id=$1 [QSA,N]
RewriteRule ^/admin/([^/]+)/ /calendar_admin/?id=$1 [QSA,N]
RewriteRule ^/user/([^/]+)/calendar/ /calendar/?id=$1 [QSA,N]
RewriteRule ^/user/([^/]+)/profile/ /profile/?id=$1 [QSA,N]

# Smarty rewrite rule the request from "/foo/bar/" to "/dispatch.php/foo/bar/"
RewriteRule     ^(.*)$    dispatch.php/$1 [L]

我如何才能使第一部分仅适用于 restful.domain.com 子域?它仍然可以重写,然后使用新 URL 执行 smarty 规则吗?

相关内容