redirect/check if available

Discuss practical ways rearrange URLs using mod_rewrite.

redirect/check if available

Postby mwe » Thu Jul 17, 2008 6:56 am

If it possible to have a mod_rewrite that does the following:

When a user visits http://www.mysite.com/tom/ (which tom doesn't exist), they get redirected to http://www.mysite.com/index.php?aff=tom

However, if the user visits http://www.mysite.com/bob/ (which does exist), they get the right site information.
mwe
 
Posts: 21
Joined: Fri Aug 10, 2007 7:12 am
Location: North Augusta, SC USA

Postby richardk » Thu Jul 17, 2008 1:09 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# If it's not a request to an existing file
RewriteCond %{SCRIPT_FILENAME} !-f
# or directory
RewriteCond %{SCRIPT_FILENAME} !-d
# rewrite /$1/ to /index.php?aff=$1
RewriteRule ^([^/]+)/?$ /index.php?aff=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 31 guests

cron