[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Mod-rewrite or other to redirect folders

Posted on 2009-12-29
8
Medium Priority
?
291 Views
Last Modified: 2012-05-08
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
0
Comment
Question by:brittonv
  • 4
  • 3
8 Comments
 
LVL 57

Expert Comment

by:giltjr
ID: 26141445
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
 
LVL 8

Author Comment

by:brittonv
ID: 26142862
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
 
LVL 57

Expert Comment

by:giltjr
ID: 26142891
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:brittonv
ID: 26145779
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
 
LVL 26

Accepted Solution

by:
arober11 earned 2000 total points
ID: 26146393
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
 
LVL 57

Expert Comment

by:giltjr
ID: 26147280
What arober11 provide will do what you want.
0
 
LVL 8

Author Comment

by:brittonv
ID: 26147923
Can I just put this within a <VirtualHost> tag?
0
 
LVL 57

Expert Comment

by:giltjr
ID: 26147946
Yes.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month18 days, 15 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question