Error 404 URL Redirection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
strangledspyder
Forum Newbie
Posts: 2
Joined: Tue Mar 31, 2009 5:25 pm

Error 404 URL Redirection

Post by strangledspyder »

I bet this involves .htaccess more than php but I wasn't sure so I am posting here anyway.

I am trying to get a url with a random string at the end to redirect to a specific php page with the string appended as a GET variable. For example:

http://www.whatever.com/Google

Becomes

http://www.whatever.com/redirect.php?q=Google

But

http://www.whatever.com/

Goes to the index.php file.

Any help would be much appreciated.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Error 404 URL Redirection

Post by requinix »

Yep, .htaccess.

Code: Select all

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* redirect.php?q=$0
strangledspyder
Forum Newbie
Posts: 2
Joined: Tue Mar 31, 2009 5:25 pm

Re: Error 404 URL Redirection

Post by strangledspyder »

Thanks. I ended up using the following and it seems to work for what I want:

RewriteEngine on
RewriteRule ^([A-Za-z0-9]+)$ /redirect.php?site=$1
Post Reply