Forum Moderators: phranque
I want to redirect a subdomain to a real directory on my server.
Here's what I got after searching this forum:
RewriteCond %{HTTP_HOST} ^sub\.mydomain\.co\.uk [NC]
RewriteRule ^(.*) /home/user/domains/mydomain.co.uk/public_html/sub/$1 [NC,L]
The problem is the '$1' part. When I remove this, or replace it with a file on the directory - it works like a charm.
But if I leave it there (and I need it, becuase I want the parameter) then I get HTTP 500 Error.
What am I doing wrong? :-(
Thanks!
Also, the length of your substitution filepath indicates that your site's DocumentRoot is likely not configured properly (or at all).
The code, assuming that you fix that DocumentRoot problem will likely look more like:
# Externally redirect to force subdomain canonicalisation
RewriteCond %{HTTP_HOST} ^sub\.example\.co\.uk [NC]
RewriteCond %{HTTP_HOST} !=sub.example.co.uk
RewriteRule ^(.*)$ http://sub.example.co.uk/$1 [R=301,L]
#
# Internally rewrite requests for "sub" subdomain to "/sub" folder
RewriteCond %{HTTP_HOST} ^sub\.example\.co\.uk
RewriteCond $1 !sub/
RewriteRule ^(.*)$ /sub/$1 [NC,L]
e.g. map the URL <the-subdomain-name>.example.co.uk/foo to the filepath /subdomains/<the-subdomain-name>/foo so that all you need test for is the "/subdomains/" path already being present in order to stop a loop, and that same test will work for any subdomain.
Jim
[edited by: jdMorgan at 10:07 pm (utc) on Sep. 30, 2009]