Forum Moderators: phranque

Message Too Old, No Replies

rewrite path

         

opalplus

5:06 am on Oct 17, 2006 (gmt 0)

10+ Year Member



Hi,

I am using this rewrite rule that works fine...

RewriteRule ^browse/([^/]+)/?$ /browse.php?id=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /browse\.php\?id=([^\ ]+)\ HTTP/
RewriteRule ^browse\.php$ /browse/%1? [R=301,L]

how can I make the occasional URL show up differently eg...
/browse.php?id=249 to /newtitle instead of /browse/249.

Is this the correct way after applying the rule above

RewriteRule ^newtitle$ /browse/249 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /browse/249\.php
RewriteRule ^browse/249\.php$ /newtitle [R=301,L]

or should i do something to the 1st code above?

thanks

jdMorgan

3:58 pm on Oct 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of 'stacking' the rewrites, requiring the first rule to format the URL so that the second rule can modify it, why not simply do the 'special' or 'new' URLs first and rewrite them directly?

RewriteRule ^newtitle/?$ /browse.php?id=249 [L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /browse\.php\?id=249\ HTTP/
RewriteRule ^browse\.php$ /newtitle? [R=301,L]

If 'newtitle' is in fact a brand-new page, then the second rewriterule (and its rewritecond) won't even be needed, since this rule is only used to remove previously-indexed dynamic URLs from search engine listings and replace them with the static, search-engine-friendly URL. Only the first rule would be needed so that your site would function when that /newtitle page is requested, and search engines will never see the /browse.php?id=249 dynamic URL, since it's an internal rewrite.

Jim

opalplus

12:45 am on Oct 18, 2006 (gmt 0)

10+ Year Member



Awesome thanks Jim.
thanks for explaining it to me aswell, really helps