URI Rewrite with fake subdomains and multiple variables
        Posted  
        
            by 
                Rich
            
        on Server Fault
        
        See other posts from Server Fault
        
            or by Rich
        
        
        
        Published on 2012-11-14T17:40:22Z
        Indexed on 
            2012/11/14
            23:02 UTC
        
        
        Read the original article
        Hit count: 246
        
Can someone please help with trying to use mod rewrite so foo.domain.com is rewritten to domain.com/p.php?s=foo and foo.domain.com/bar to domain.com/p.php?s=foo&p=bar?
Currently my .htaccess is:
RewriteEngine On
# Remove www
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
# Rewrite subdomain etc.
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/?$ p.php?s=%1&p=$2 [QSA,L,NC]
But I can't work out how to grab the second variable (being optional and after a slash at the end of the URI. I've tried changing the end of the condition to ?/(.*)$, but to no avail and my mod rewrite skills are certainly naff!
© Server Fault or respective owner