logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: mod_rewrite with certain parameters
Author
Mark1979



Joined: 21 Jun 2010
Posts: 3

PostPosted: Mon 21 Jun '10 15:52    Post subject: mod_rewrite with certain parameters Reply with quote

Hi Guys,

I hope someone can help with this problem, it's driving me mad!

I have a folder on my website with 000's of banners which people are linking to. I want to redirect these to new banners of the same size.

I have looked at Mod_Rewrite and ReWrite rules but cant seem to get it right. The code should...

-Look for '468x60' in the filename
-If it does, redirect to another file.

E.g.

www.mysite.com/banners/banner468x60.gif
www.mysite.com/banners/another468x60.gif

would redirect to

www.anothersite.com/newbanners/banner468x60.gif

but

www.mysite.com/banners/banner120x60.gif would not be redirected.

Hope that makes sense.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 21 Jun '10 16:01    Post subject: Reply with quote

I think a custom error handler for that folder could be a solution. Maybe a server side script which handles 404 errors and than redirects to the new folder.

e.g
Code:

ErrorDocument 404 /banners/my_404_handler.php
Back to top
Mark1979



Joined: 21 Jun 2010
Posts: 3

PostPosted: Mon 21 Jun '10 16:07    Post subject: Reply with quote

Hey James,

Thanks for the quick response, that does sound like a good option. Smile
Back to top
Mark1979



Joined: 21 Jun 2010
Posts: 3

PostPosted: Mon 21 Jun '10 16:32    Post subject: Reply with quote

Hmm, that doesnt seem to work either.

It seems that HTTP_REFERER doesn't work for 404's - or I can't get them to work anyway. the Http referer just shows my_404_handler.php as the referring page.
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Mon 21 Jun '10 23:04    Post subject: Reply with quote

For the ErrorDocument route ... is FileInfo one of the AllowOverrides for the folder or folder/s above it in the tree? The only reason I cannot think of that it would not work as this is a pretty standard way to serve up custom error documents.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 21 Jun '10 23:07    Post subject: Reply with quote

You are using the wrong variable Wink Try $_SERVER['REQUEST_URI']


---- edit ---


There are two different variables that I find very useful in Caching and similar.

$_SERVER['REQUEST_URI'] and $_SERVER['REQUEST_URL']

URI provides the entire request path (/directory/file.ext?query=string)
URL provides the request path, without the query string (/directory/file.ext)
It also differs from __FILE__ in that it's not the file name. So, if you go to /directory/anotherfile.ext and get silently redirected to file.ext, these variables are anotherfile.ext, while __FILE__ is still file.ext.
Back to top


Reply to topic   Topic: mod_rewrite with certain parameters View previous topic :: View next topic
Post new topic   Forum Index -> Apache