You are not logged in.

#1 2009-02-17 06:16:13

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

[SOLVED] Apache redirect all paths to root

Hey all,

For some reason, I have the A records for domain benchall.com pointed to my VPS. Not my domain, no idea who owns it or why they're trying to host it on my server. Attempted contact with the registered owner has been futile. So, I've created it as a virtual host with short page asking the owner to fix their DNS, and then redirect to meatspin.com big_smile

Problem is, most of the requests going to this domain are for paths below the root such as images/star.gif /YouBench and various other CSS and image files.

What redirection rule can I put in apache to redirect ANY request for any path under www.benchall.com to /index.html?
eg, www.benchall.com/images/star.gif --> www.benchall.com
eg, www.benchall.com/YouBench/ --> www.benchall.com
eg, benchall.com/images/star.gif --> www.benchall.com

I've tried various versions of the below config, but they all result in a redirect loop sad

       RewriteEngine On
       RewriteCond %{HTTP_HOST} !^.*benchall\.com/index\.html$
       RewriteRule ^(.*)$ http://www.benchall.com/index.html [R=permanent,L]

Last edited by fukawi2 (2009-02-18 00:48:27)

Offline

#2 2009-02-17 13:45:35

aglarond
Member
From: Texas, USA
Registered: 2008-11-20
Posts: 129

Re: [SOLVED] Apache redirect all paths to root

I have the same thing on one of my sites, but my last line is a little different:

RewriteRule (.*) http://wherever.com [R=301,L]

-mS

Offline

#3 2009-02-17 22:06:20

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: [SOLVED] Apache redirect all paths to root

301 is a permanent redirect, so I think they'll do the same thing... I'll give it a shot without the anchoring on the regex though...

Nope sad

Redirect Loop

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

Offline

#4 2009-02-18 00:33:29

foutrelis
Developer
From: Athens, Greece
Registered: 2008-07-28
Posts: 705
Website

Re: [SOLVED] Apache redirect all paths to root

First of all, I would suggest that you remove the redirection to meatspin.com. I highly doubt that the domain you posted gets more than 10 visits/month, but meh, being ethical never hurt anyone. smile

Secondly, it would be more appropriate to issue a 503 error code which would indicate that the service provided on this domain is currently unavailable. You can do this with the following PHP script and .htaccess files:

index.php:

<?php header("HTTP/1.1 503 Service Unavailable"); ?>
<html>
    <head>
        <title>Unauathorized DNS</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
        <p align='center'>
        This domain (benchall.com) has set their DNS to this host without authorization.
        </p>

        <p align='center'>
        <b>If you are the owner of this domain, please update your DNS urgently to use correct DNS settings.</b>
        </p>
    </body>
</html>

.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php [L]
</IfModule>

Offline

#5 2009-02-18 00:48:16

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: [SOLVED] Apache redirect all paths to root

Sweet, that works foutrelis - thank you smile

I've added the 403 in, but I've left the redirection to meatspin, just because I'm a bastard tongue

Offline

#6 2009-02-18 00:51:10

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: [SOLVED] Apache redirect all paths to root

foutrelis wrote:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Off-topic, but I seem to have missed the point in time where everyone started closing HTML tags with /> instead of just >

Can someone explain to me why we have moved to this practice? I just don't get it, it doesn't seem to change anything apart from extra typing, which we all know if bad.

Offline

#7 2009-02-18 02:34:29

foutrelis
Developer
From: Athens, Greece
Registered: 2008-07-28
Posts: 705
Website

Re: [SOLVED] Apache redirect all paths to root

XHTML requires all tags be closed. This is not the case with HTML. The former has (mistakenly?) gained a lot of popularity in recent years, not sure how that came to be though. :>

Have a read at the wikipedia entry about XHTML for juicy details.

Offline

#8 2009-02-18 02:57:10

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: [SOLVED] Apache redirect all paths to root

Cheers smile

Offline

Board footer

Powered by FluxBB