.htaccess redirect
April 22, 2013 4:24 PM   Subscribe

I would like for http://bookmarks.mydomain.com/ to redirect to http://www.mydomain.com/subdir/www/. I suspect that I can achieve this with an .htaccess file, but I am not smart enough to figure how. Can anyone help?
posted by Proginoskes to Computers & Internet (5 answers total) 1 user marked this as a favorite
 
I believe you want to do a 301 Redirect:

Webmaster Tools article
posted by humboldt32 at 4:40 PM on April 22, 2013


Set the bookmarks.mydomain.com virtual host to a new empty directory.

In that directory make this .htaccess file:

RewriteEngine ON
RewriteRule ^(.*) http://www.mydomain.com/subdir/www/$1

This will make any request to bookmarks.mydomain.com get redirected to http://www.mydomain.com/subdir/www/, and any request for bookmarks.mydomain.com/whatever will be redirected to http://www.mydomain.com/subdir/www/whatever
posted by aubilenon at 4:55 PM on April 22, 2013


If you would rather bookmarks.mydomain.com/whatever to go back to http://www.mydomain.com/subdir/www/, and drop the /whatever remove the $1 from the right side of the rule.
posted by aubilenon at 4:58 PM on April 22, 2013


Best answer: If you host bookmarks.mydomain.com in its own virtual host, do a simple Redirect statement. Don't get mod_rewrite involved!
Redirect / http://www.mydomain.com/subdir/www/
If both domains are hosted on the same virtual host, then I probably would get mod_write involved:
RewriteEngine on
RewriteCond %{HTTP_HOST} =bookmarks.mydomain.com
RewriteRule ^(.*) http://www.mydomain.com/subdir/www/$1 [R,L]
Either of those need to be in your server config or the document root directory. You can't place it in "/subdir/www/"; Apache won't know to look there.
posted by sbutler at 5:21 PM on April 22, 2013 [1 favorite]


You have good direct answers to your question. However, I've occasionally encountered people using the word redirect when they mean either an additional virtual host with its own DocumentRoot (i.e. a hostname pointing directly to a folder somewhere such that the hostname does not change in the URL) or a reverse proxy (i.e. something that retrieves content from another location on the web and presents it under the hostname someone typed in for the URL). Also, you don't mention whether you have the bookmarks.mydomain.com doing anything so far. So if by chance a redirect isn't exactly the thing you had in mind, those would be the points to clarify.
posted by Monsieur Caution at 5:50 PM on April 22, 2013 [1 favorite]


« Older YANMD. What are some possible reasons my heels...   |   How do I respond to resume rejection because of... Newer »
This thread is closed to new comments.