Link to home
Start Free TrialLog in
Avatar of brittonv
brittonvFlag for United States of America

asked on

Mod-rewrite or other to redirect folders

Greetings,

I want to change URL's but not my folder structures.

I have:

www.domain.com/folder1/folder2/file.exe
www.domain.com/folder3/folder24/secondfile.exe
.... 10000 times

Is there away in Apache that I can redirect www.domain.com to another.domain.com but keep the folder paths.

So if someone goes to www.domain.com/folder1/folder2/file.exe they will be redirected to another.domain.com/folder1/folder2/file.exe?

I know how to do it with mod-rewrite on a folder by folder basis, but I don't' want to do it 1000's of times for every folder.

Thanks
Avatar of giltjr
giltjr
Flag of United States of America image

Using the example from the Apache URL Re-write page modified just a bit

RewriteCond %{HTTP_HOST}   ^www\.example\.com [NC]
RewriteRule ^/(.*)         http://another.example.com/$1 [L,R]



http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Avatar of brittonv

ASKER

would this allow me to host a www.example.com page as well?

Meaning www.example.com goes to an actual index.html page while www.example.com/* goes to the another.example.com/*
No it would not, it would redirect all requests for www.example.com to another.example.com.

If you want to redirect specify folders, you need to either list all as a condition, or come up with a regular expression that would catch what you want without catching things you don't want.

Do you just want www.example.com/folder2/* redirected to anotherhost.example.com/folder1/folder2/* ?

Or are there other patterns?
There are patterns.

I need /folder1/folder2/file.exe to match the same directory on the new server.

However if they go to the root www.example.com I want to display a message that they this domain is no longer valid and have them redirect to another URL.  SO

www.example.com/folder1/folder2/file.exe would redirect to
fw.newdomain.com/folder1/folder2/file.exe

While if someone goes to www.example.com, they would see a message saying:

The website you are trying to reach is no longer valid, please wait while you are redirected or click here.

and then they would be sent to www.newdomain.com/newpage.html

I want people to still get their files if they access the old url, but at the same time people going to the home page should be redirected.

ASKER CERTIFIED SOLUTION
Avatar of arober11
arober11
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What arober11 provide will do what you want.
Can I just put this within a <VirtualHost> tag?
Yes.