Forum Moderators: phranque

Message Too Old, No Replies

Send All Requests to One Page

mod_rewrite

         

kernelpanic

8:12 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



I'm about to launch a new site that has multiple domains pointing to it, and it's going to take a few hours to everything up and running. In the meantime, I'd like to redirect ALL requests to backsoon.html at the root of the site. Can mod_rewrite do this?

gergoe

8:35 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



With ease; check out the following resources:

Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]

kernelpanic

8:49 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



I looked at the Apache docs and did some extensive Googling before asking my question. I still don't fully understand how to accomplish this. Any examples would be much appreciated.

jdMorgan

9:22 pm on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kernelpanic,

Welcome to WebmasterWorld!

Here are some examples [google.com].

Jim

kernelpanic

9:57 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



Does this look correct?

RewriteRule /(.*).tpl /backsoon.html [R=301,L]

jdMorgan

10:24 pm on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, it depends on what resources you want to redirect and how they are named. The pattern you use should match all files you want to redirect, and not match all files (e.g. images) that you don't want to redirect.

Then you have to decide if you want to do an internal rewrite or an external redirect. In this case, you could do either an internal rewrite or a 302-Moved Temporarily external redirect. The difference is that an internal rewrite will simply substitute the contents of backsoon.html for any requested resource that matches your RewriteRule pattern, leaving the address in the browser address bar unchanged, whereas an external redirect will send a message back to the browser saying, "That resource has moved, ask for at this address: http:www.example.com/backsoon.html". The browser will then re-request the resource from that URL.

For an internal rewrite, I'd suggest:


Options +FollowSymLinks
RewriteEngine on
RewriteRule \.tpl$ /backsoon.html [L]

and for an external redirect:

Options +FollowSymLinks
RewriteEngine on
RewriteRule \.tpl$ http://www.example.com/backsoon.html [R=302,L]

You should omit the first two directives if they are already present in the httpd.conf or .htaccess file you're using -- I'm not sure which of those files you intend to use.

Alternatively, you could use:


RedirectMatch 302 \.tpl$ http://www.example.com/backsoon.html

Jim