Forum Moderators: phranque

Message Too Old, No Replies

Rewriting a dynamic URL to a search engine friendly static URL

I am trying to rewrite 3 variables in a single url and am having problems

         

atlas007

6:37 pm on Jul 18, 2005 (gmt 0)

10+ Year Member



In the sample below "id", "c", and "iss" are variables in my dynamic URL. id and c seem to work fine without iss but as soon as I add that 3rd variable, id is the only one that still works. Any help would be great.

## URL that I am trying to Rewrite
## NewsItem.php?id=1&c=C-P&iss=news_vol1issue2

## rewrite would look like this
## id1cC-Pissnews_vol1issue2.htm

RewriteEngine on
RewriteBase /

RewriteRule ^id([^.]+)c([^.]+)iss([^.]+).*$ NewsItem.php?id=$1&c=$2&iss=$3 [T=application/x-httpd-php]

jdMorgan

7:57 pm on Jul 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



atlas007,

Welcome to WebmasterWorld!

The pattern
^id([^.]+)c([^.]+)iss([^.]+).*$
will not match your friendly URL as intended. I'd suggest a review of the regular-expressions tutorial cited in our forum charter [webmasterworld.com].

A better rule might be:


RewriteRule ^idc(.+)iss([^.]+)\.htm$ /NewsItem.php?id=1&c=$1&iss=$2 [[T=application/x-httpd-php],L]

Jim

atlas007

7:40 pm on Jul 19, 2005 (gmt 0)

10+ Year Member



Thank you JD!

The Regular Expressions Tutorial at the bottom of the Forum Charter you provided was what I needed. It made me take a different approach. Here is the working file for reference. I had a hyphen in the "c" variable in the original post. ie. c=C-P. By changing the variable to "CP" instead of C-P, and finessing the regular expression I was able to get it to work. Thanks for the direction.

RewriteEngine on
RewriteBase /
RewriteRule ^id([0-9]+)c([A-Za-z]+)iss([^.]+)\.htm$ /NewsItem.php?id=$1&c=$2&iss=$3 [T=application/x-httpd-php]

jdMorgan

1:58 am on Jul 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd still recommend making the compare case-insensitive using [NC]: It will reduce the number of compares by half.

RewriteRule ^id([0-9]+)c([b][a-z][/b]+)iss([^.]+)\.htm$ /NewsItem.php?id=$1&c=$2&iss=$3 [[b]NC,[/b]T=application/x-httpd-php]

Jim

atlas007

6:24 pm on Jul 21, 2005 (gmt 0)

10+ Year Member



Thank's again. That makes perfect sense.