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
LVL 8
brittonvAsked:
Who is Participating?
 
arober11Connect With a Mentor Commented:
The following in your httpd.conf or .htaccess should do:

RewriteEngin On
RewriteCond %{REQUEST_URI} !^[/]*$
RewriteRule ^.*         http://newdomain.com%{REQUEST_URI} [L,R=301]

Note: If the two domain's are hosted by the same apache instance, you need to add back the following line:

RewriteCond %{HTTP_HOST}    ^www\.example\.com [NC]
0
 
giltjrCommented:
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
0
 
brittonvAuthor Commented:
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/*
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
giltjrCommented:
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?
0
 
brittonvAuthor Commented:
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.

0
 
giltjrCommented:
What arober11 provide will do what you want.
0
 
brittonvAuthor Commented:
Can I just put this within a <VirtualHost> tag?
0
 
giltjrCommented:
Yes.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.