You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Jack Knowlton <jk...@vp44.com> on 2009/11/14 17:34:38 UTC

[users@httpd] Redirect ANY request to one page

Hi all.
I am trying to have apache (2.2.14-1 from Debian) redirect any request to
a certain page. In the server root I have the single file "park.html" and
I want that all requests for resources (documents as well as folders) on
that domain be redirected to that particular page.
To be specific:
* Request: "www.domain.com" -> redirect "www.domain.com/park.html"
* Request: "www.domain.com/otherpage.php" -> "www.domain.com/park.html"
* Request: "www.domain.com/dir1/hello.cgi" -> "www.domain.com/park.html"
ecc..

I currently tried using the following rule: "RedirectMatch permanent
^(.*)$ /park.html" but it doesn't seem to work (results in an infinite
loop).
Since I need the redirect badly, I set up 404s to go to "park.html" but I
think that won't go so well with robots.
Any suggestions?
Thanks.

-JK


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Redirect ANY request to one page

Posted by Jack Knowlton <jk...@vp44.com>.
On Sat, November 14, 2009 6:01 pm, Philip Wigg wrote:
> Hi,
>
> Try using mod_rewrite. This configuration should work...
>
> RewriteEngine On
> RewriteCond %{REQUEST_URI} !^/park.html$
> RewriteRule (.*) /park.html [L, R]
>
> This redirects any request except park.html. Note that if park.html
> contains an image, css, or whatever, it's important to also have a
> condition to not redirect that image. For example, let's say park.html
> references an image called logo.gif in a folder called 'images', you
> could use:-
>
> RewriteEngine On
> RewriteCond %{REQUEST_URI} !^/park.html$
> RewriteCond %{REQUEST_URI} !^/images/logo.gif$
> RewriteRule (.*) /park.html [L, R]
>
> Cheers,
> Phil.
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


It works great. Thanks for the help!

-JK


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Redirect ANY request to one page

Posted by Philip Wigg <ph...@philipwigg.co.uk>.
Hi,

Try using mod_rewrite. This configuration should work...

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/park.html$
RewriteRule (.*) /park.html [L, R]

This redirects any request except park.html. Note that if park.html
contains an image, css, or whatever, it's important to also have a
condition to not redirect that image. For example, let's say park.html
references an image called logo.gif in a folder called 'images', you
could use:-

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/park.html$
RewriteCond %{REQUEST_URI} !^/images/logo.gif$
RewriteRule (.*) /park.html [L, R]

Cheers,
Phil.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Redirect ANY request to one page

Posted by Glen Barber <gl...@gmail.com>.
On Sat, Nov 14, 2009 at 11:34 AM, Jack Knowlton <jk...@vp44.com> wrote:
> Hi all.
> I am trying to have apache (2.2.14-1 from Debian) redirect any request to
> a certain page. In the server root I have the single file "park.html" and
> I want that all requests for resources (documents as well as folders) on
> that domain be redirected to that particular page.
> To be specific:
> * Request: "www.domain.com" -> redirect "www.domain.com/park.html"
> * Request: "www.domain.com/otherpage.php" -> "www.domain.com/park.html"
> * Request: "www.domain.com/dir1/hello.cgi" -> "www.domain.com/park.html"
> ecc..
>
> I currently tried using the following rule: "RedirectMatch permanent
> ^(.*)$ /park.html" but it doesn't seem to work (results in an infinite
> loop).

I would imagine that is because park.html is trying to redirect to
itself.  You should have a rule before this to check if the page is
park.html, then stop processing.

> Since I need the redirect badly, I set up 404s to go to "park.html" but I
> think that won't go so well with robots.
> Any suggestions?
> Thanks.
>
> -JK
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>



-- 
Glen Barber

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org