1

I'm trying to setup several rewrite rules that allow a restful url structure to exist, but only on a certain subdomain. Several subdomains already point to the shared codebase. I also have an existing rewrite in place in order to use PHP smarty, which already captures everything. All subdomains including the restful one need to redirect there as a final step.

Finally, for convenience I'd like to try to put the subdomain into a query string variable if possible as well, to avoid trying to extract it programmatically later.

I'm new to mod_rewrite and am having trouble getting all these to work together... here is my mixed attempts so far, which doesn't quite work all together.

# 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]

How can I make the first section only apply for the restful.domain.com subdomain? Can it still rewrite, then do the smarty rule with the new urls?

Miro
  • 111
  • 2
  • Play around using this: http://htaccess.madewithlove.be/ which helps debugging and read http://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever – ETL Mar 09 '14 at 22:47

0 Answers0