Modrewrite based on a ?id number

Discuss practical ways rearrange URLs using mod_rewrite.

Modrewrite based on a ?id number

Postby deef » Wed Jun 17, 2009 3:09 pm

I wish to use mod_rewrite to make better urls.. and one way it's working.. but I have some problem with my mod rewrite when I wish to use a ID number. I don't quite understand the basics of mod rewrite...

I wish to have 3 possibility's:
* Or Id = a random 3 digit number...
* Or Id = 'new'
* Or id does'nt exist

Based on the above possibility's, the mod rewrite has to act, like I have written... But I'm getting always a 404 page.

Can someone help me out please ?

Thanks,

Deef

Code: Select all
#id must be RANDOM 3 DIGIT NUMBER for example id=456
RewriteRule ^(.+)/clips-(.+)\?id=456$ redirect.php?subd1=$1&link1=$2 [L]

#id must be NEW so id=new (for the redirect) -- I don't need the variables here... becausse I read out the url
RewriteRule ^(.+)/clips-(.+)\?id=new$ redir.php [L]

#There is NO ID, it does not exist
RewriteRule ^(.+)/clips-(.+)$ redirect.php?subdomain=$1&link=$2 [L]
deef
 
Posts: 15
Joined: Thu Jun 08, 2006 1:20 pm

Postby richardk » Wed Jun 17, 2009 3:25 pm

Query strings are matched with the %{QUERY_STRING} variable and RewriteConds.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?id=[0-9]{3}(&.*)?$ [NC]
RewriteRule ^(.+)/clips-(.+)$ /redirect.php?subd1=$1&link1=$2 [L]

RewriteCond %{QUERY_STRING} ^(.*&)?id=new(&.*)?$ [NC]
RewriteRule ^(.+)/clips-(.+)$ /redir.php [L]

RewriteRule ^(.+)/clips-(.+)$ /redirect.php?subdomain=$1&link=$2 [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 26 guests

cron