views:

17

answers:

1

hi all this is my first question, i know i have read heaps of other post on ReWrites but i still can not get this correct.

simple URL i have now: /articlesView.php?id=6&title=Fisher-&-Paykel-Australian-Age-Championships!-2006

i would like to change it to: /articles/6/Fisher-&-Paykel-Australian-Age-Championships!-2006.php

any help would be most appreciated.

Ben

A: 

Try something along the lines of:

RewriteCond %{REQUEST_URI} ^/articles/([0-9][0-9]*)/(..*).php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /articlesView.php?id=%1&title=%2 [L]

I'm sure there is better ways since this is of the top of my head, but it should point you in the right direction.

First line checks that the incoming request is formatted as /articles/{number}/{title}.php Second line checks that it isn't the path to a real file. Third line rewrites it to the original format.

Since the new format will most likely through out the pathing of your css/javascript/image files, you will probably require a second rule similar to:

RewriteCond %{REQUEST_URI} ^/articles/([0-9][0-9]*)/(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /%1 [L]

This will grab everything else and remove the extra pathing that has been added

Dan McGrath