Forum Moderators: phranque

Message Too Old, No Replies

.htaccess file to redirect anything under a sub dir to one new place

htaccess redirect - yet another

         

netmatters

2:07 pm on May 13, 2009 (gmt 0)

10+ Year Member



I want to be able to redirect any file requests from a directory to a new url..

for example:

subdomain.mydomain.com/dir1/filename.extensio

to go to www.newdomain.com

but i also want any subsequent directories or files to also point at newdomain.com

ie. subdomain.mydomain.com/dir1/dir2/filename.extension
to go to: www.newdomain.com

is it possible to write a .htaccess file to do this. I have tried to google it and dont fully understand the more complex htaccess files.

Also

Does anyone know of any good tutorials which will help with this in the future?

jdMorgan

7:23 pm on May 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See our Apache Forum Library (link at top of this page) for examples, and see the resources cited in our Forum Charter for background info.

You can use mod_rewrite:


RewriteRule %{HTTP_HOST} =subdomain.olddomain.com
RewriteRule ^dir1/ http://www.newdomain.com/ [R=301,L]

As you appear to require, this rule 'drops' the subdirectory and filepaths; That is, it redirects requests for subdomain.olddomain.com/dir1/<anything or nothing> to www.newdomain.com/ and does not pass the subdirectory or filename to www.newdomain.com

Jim

netmatters

8:19 am on May 14, 2009 (gmt 0)

10+ Year Member



I will give it a try in a bit. Many thanks for the information. much appreciated.

Andy.