change URL while passing DATE Variable

Discuss practical ways rearrange URLs using mod_rewrite.

change URL while passing DATE Variable

Postby younker1983 » Tue Jun 03, 2008 3:04 am

Hi,

my current URL is :

http://mysite.com/abc.php?cat=maincatone&dat=2008-06-03

want to convert it into

http://mysite.com/2008-06-03/maincatone.html


how to pass the variable to abc.php ?? like now i m passing :

abc.php?cat=maincatone&dat=$_SESSION[dat]


wht shld i write in .htaccess file ?


Thanks,
younker1983
 
Posts: 3
Joined: Sat May 17, 2008 12:52 am

Postby TeckniX » Tue Jun 03, 2008 1:25 pm

Should be something along those lines...

Code: Select all
Options +FollowSymLinks
RewriteEngine on

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([0-9\-]+)\/([a-zA-Z]+)\.html$ abc.php?cat=$2&dat=$1 [QSA,L]



I haven't tested it, but i figured this way you could give a twirl while waiting for richardk to chime in :)
TeckniX
 
Posts: 38
Joined: Tue Mar 27, 2007 12:18 pm

Postby richardk » Tue Jun 03, 2008 2:16 pm

I'd match the date more strictly so you don't need the conditions (you would only need the files test anyway, as it ends in .html and that is unlikely in a directory name).
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([12][0-9]{3}-(?:0[1-9]|1[0-2])-(?:0[1-9]|2[0-9]|3[01]))/([a-z]+)\.html$ /abc.php?dat=$1&cat=$2 [NC,QSA,L]

The year range could be matched more strictly.
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 88 guests

cron