Converting two formats of dynamic to static

Discuss practical ways rearrange URLs using mod_rewrite.

Converting two formats of dynamic to static

Postby yalamber » Sun Aug 31, 2008 9:07 am

hello below are two formats of the dynamic urls
1. index.php?do=x(alphabets)&type=y(alphabet)
2. index.php?do=x(alphabets)&type=x(alphabet)&id=z(numeric)
is this the correct rewrite rule for these two
Code: Select all
RewriteRule ^do/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ index.php?do=$1&type=$2 [L,QSA]
  RewriteRule ^do/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([0-9]+)$ index.php?do=$1&type=$2&id=$3 [L,QSA]

what i want the static url like is do/x/y and do/x/y/z
Also i want to do 301 redirect of the old static urls i have made. it was like x/y for the first one and x/z.html for the second one. how can i do that.
Posts: 15
Joined: Fri Sep 07, 2007 12:52 am
Location: biratnagar

Postby richardk » Sun Aug 31, 2008 9:45 am

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# /x/z.html
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([A-Za-z0-9-]+)/([0-9]+)\.html$ /do/$1/$1/$2 [R=301,L]

# /x/y
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ /do/$1/$2 [R=301,L]

RewriteRule ^do/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ /index.php?do=$1&type=$2 [QSA,L]
RewriteRule ^do/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([0-9]+)$ /index.php?do=$1&type=$2&id=$3 [QSA,L]
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 7 guests