Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule: help needed with regex

         

ro1960

4:39 pm on Aug 17, 2008 (gmt 0)

10+ Year Member



I am trying to set up clean URLs on my site. I've found some very good tutorials on the internet, but I am having trouble writing my own regex.

The un-clean URL is in this format:

http://www.example.com/pl.php?p=news_item.php&section=news&id=93178

And I would like the clean URL to look like this:

http://www.example.com/news/93178

Here's what I have in my .htaccess file and it doesn't work:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/?(news)/([a-zA-Z_]+)$ pl.php?p=news_item&section=news&id=$1 [L]
</IfModule>

[edited by: jdMorgan at 12:18 am (utc) on Aug. 18, 2008]
[edit reason] example.com [/edit]

g1smd

6:13 pm on Aug 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A. The [a-zA-Z_] doesn't match numbers, but your example URL has numbers at that position. I would use ([0-9]{5}) instead.

B. You are reusing $1 in the rewrite, but surely it is $2 that would contain the data you need (notwithstanding fixing point A above).

C. There's a stray .php in your unclean example URL that doesn't match anywhere in your rule.

ro1960

9:25 pm on Aug 17, 2008 (gmt 0)

10+ Year Member



Thanks I fixed the problems and it works now.