Forum Moderators: phranque

Message Too Old, No Replies

Help with a RewriteRule

         

endtheme

11:46 pm on May 28, 2008 (gmt 0)

10+ Year Member



I want a RewriteRule that will take any of the following URLs:

* mysite.com/article/347953/name_of_article.html
* mysite.com/article/347953/name_of_article/
* mysite.com/article/347953/name_of_article
* mysite.com/article/347953/
* mysite.com/article/347953

And rewrite them to this index.php?module=article&id=347953, essentially discarding everything after the id number.

I have come up with my own RewriteRule and it works on my home server (WAMP5 using Apache2), however when I upload the .htaccess file to my site which is using Apache/1.3.39, the RewriteRule does not work -- I get a 404 error.

RewriteRule ^article/(d+)(/[A-Za-z0-9_/]+)(.html)?$ index.php?module=article&id=$1 [NC]

Is there an error in my RewriteRule? Perhaps there is a better way to write it.

endtheme

11:58 pm on May 28, 2008 (gmt 0)

10+ Year Member



I tried:

RewriteRule ^article/(\d+)(.*)? index.php?module=article&id=$1 [NC]

as well, as it seems more simplified, and I still get a 404.

g1smd

12:03 am on May 29, 2008 (gmt 0)

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



RewriteRule ^article/([0-9]{6})/ /index.php?module=article&id=$1 [L]

I assumed, in the light of no other examples, that the ID is always numeric and always six digits long.

You don't need to end-anchor this pattern, nor do you need to "collect" any characters after the second slash.

I would note that this rewrite will give you Infinite Dupliccate Content.

Malformed links to your articles will be indexed as new URLs, as will stuff like yoursite.com/article/347953/this_product_is_dangerous and yoursite.com/article/347953/we_are_criminals.

Bad move.

endtheme

12:29 am on May 29, 2008 (gmt 0)

10+ Year Member



The ID is always number, however the length of the digits vary.

"we_are_criminals" Haha! Nice example.

endtheme

12:56 am on May 29, 2008 (gmt 0)

10+ Year Member



P.S. What does the [L] flag do?