Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Play around using this: htaccess.madewithlove.be which helps debugging and read serverfault.com/questions/214512/… –  ETL Mar 9 at 22:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.