Darren Riches
Darren Riches

Reputation: 149

Redirect all files in folder to a new sub domain using htacess

I need to use a .htaccess file to redirect all the pages, files and URL permutations within this IP address website, for example:

http://123.456.11.222/~account/downloads/customerxyz/oneofmyfiles.zip
http://123.456.11.222/~account/downloads/customer123/example
http://123.456.11.222/~account/downloads/newcustomer/test.jpg
...etc

to a new sub-domain like this

http://sub.newdomain.com/downloads/customerxyz/oneofmyfiles.zip
http://sub.newdomain.com/downloads/customer123/example
http://sub.newdomain.com/downloads/newcustomer/test.jpg
...etc

What is the most efficient way of doing this so all files and URL's in the downloads folder are redirected to the new location?

Thank you.

Upvotes: 1

Views: 37

Answers (1)

anubhava
anubhava

Reputation: 785246

Create a /~account/downloads/.htaccess file with these rules:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^sub\. [NC]
RewriteRule (.+) http://sub.newdomain.com/downloads/$1 [L,R=302,NE]

Upvotes: 1

Related Questions