htaccess Subdomain Redirection
August 8th, 2008My blog is set up as a subdomain to my main site so http://bobpeers.com/blog/ should really serve the content from http://blog.bobpeers.com.
Just recently I noticed that link pointing to my blog directories but accessed through the main site were not returning 404 pages for missing pages. For example a link pointing to http://bobpeers.com/blog/page-not-here would just serve the content from http://bobpeers.com. To force requests to the blog to be server by the subdomain i just added this line to my .htaccess file.
Redirect permanent /blog http://blog.bobpeers.com
Now any request for a page under the blog subdirectory will be permanently (http code 301) redirected to http://blob.bobpeers.com, so for example:
request http://bobpeers.com/blog/2008/08/page serves http://blog.bobpeers.com/2008/08/page
March 10th, 2009 at 1:01 pm
A good explanation you can find here http://blog.gwebtools.com/apache-htaccess-subdomain-redirect-rules/
April 28th, 2009 at 3:04 pm
[...] links >> subdomain Hosting Control Center: Domain Management Saved by zarix on Wed 22-4-2009 htaccess Subdomain Redirection Saved by Antrozous on Fri 10-4-2009 Tutorial: How To Run Affiliate Ads On Ad Networks Saved by [...]
November 9th, 2009 at 7:02 am
Really Apprice Code. I have One issue, please help me. My issue is I have url http://subdomain.mydomain.com and want to redirect them http://mydomin.com/folder1/index.php?user=subdomain. but I dont want to change URL in addressbar so in addressbar the url should be http://subdomain.mydomain.com. What i have to do? My .htaccess code is
=================================
#RewriteCond %{HTTP_HOST} !^www\.mydomain.com [NC]
#RewriteCond %{HTTP_HOST} ([^.]+)\.mydomain.com [NC]
#RewriteRule ^(.*)$ http://mydomain.com/folder1/index.php?user=%1 [L]
=================================
It redirect correctly, But Unfortunitly, it affect addressbar, so it’s useless for me. Please help me. What I have to do? Thanks in advance.