Forum Moderators: phranque
My webhosting service (via cPanel) gives me the option of creating a subdomain, then redirecting. The problem, if I understand this properly, is that this creates an external redirect, which re-writes the address in the browser URL.
Here's the code from the .htaccess file in the subdomain directory, automatically generated by cPanel:
==========
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example1.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example1.example.com$
RewriteRule ^.*$ "http\:\/\/www\.example\.com\/index\.php\/site\/example1\/" [R=302,L]
==========
My questions are:
1. Do I understand correctly that to do an internal redirect, I want to modify the .htaccess file for the primary domain, and not the subdomain?
2. What is it about the syntax above that specifies this is an external redirect, and how do I change it to an internal redirect?
[edited by: engine at 7:24 am (utc) on May 7, 2009]
[edit reason] examplified [/edit]
The effects of this are that the path requested by the visitor will be lost, and the example.com/site/example1/ will appear in the visitor's browser address bar.
2. For servers where all subdomains (including the www subdomain of example.com) are mapped to the root directory, the following root-level .htaccess code is typical. This is an internal rewrite, not a redirect. However, since I do not know how your server is configured or how you wish to handle your new subdomain, I do not claim that this will work for you.
# If the request is not for the the main domain or the www subdomain
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com
# get the requested subdomain name into variable %2
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
# and if not already rewritten to subdomain's subdirectory
RewriteCond $1 !^site/
# internally rewrite to prefix "/site/<subdomain-name>/" to the client-requested URL-path
RewriteRule ^(.*)$ /site/%2/$1 [L]
Jim