Hi all , have read Nintendos excellent post on htaccess but not sure if its htaccess or php redirect im looking at.(im experimenting) I have domain www.domain.com I have 5 directorys inside. So www.domain.com/dir1 ( for example) I have ( example ) 5 subdomains on a domain to match dirs ( so dir1.domain.com) Im looking to redirect dir1.domain.com to www.domain.com/dir1 but still preserving the domain dir1.domain.com. I know I could setup hosting to point dir1.domain.com to /public_html/dir1. *But* All domains point to /public_html These arent actually directorys , they are rewritten categorys. Any ideas
You can solve this with either PHP or RewriteRules. In PHP: <?php if(stristr($_SERVER['HTTP_HOST'], "dir1.domain.com")) { header("Location: http://www.domain.com/dir1", TRUE, 301); exit(); } ?> PHP: With RewriteRules: RewriteCond %{HTTP_HOST} dir1.domain.com [NC] RewriteRule .* http://www.domain.com/dir1 [R=301,L] Code (markup): Both versions will behave exactly the same way, each doing a case-insensitive comparison of the hostname with each directory name and if it matches the directory names, respond with a 301 redirect to the correct directory on the www domain.