Forum Moderators: phranque

Message Too Old, No Replies

Problems with SEO urls

Problems with SEO urls

         

pftodd

5:11 pm on Jun 29, 2009 (gmt 0)

10+ Year Member



Hi
I've been trying to generate SEO urls in my .htaccess file, but have encountered a problem. I'm tyring to generate urls for more than one dynamic file. My code is:


RewriteEngine On
RewriteRule ^(.*)/$ content.php?url=$1 [L]
RewriteRule ^news/(.*)/$ show_news.php?url=$2 [L]

The problem is, when I point my browser to the second rewrite rule, e.g. url.com/news/example/, it redirects me to the location of the first rewrite rule, so the output would be like url.com/content.php?url=example, where it should be url.com/show_news.php?url=example.

How do I need to edit my code for both the rewrite rules to work in conjunction?

Thank you.

jdMorgan

10:28 pm on Jun 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Put the more-specific rule first and make both patterns more specific:

RewriteEngine On
#
RewriteRule ^news/([^/]+)/$ show_news.php?url=$2 [L]
RewriteRule ^([^/]+)/$ content.php?url=$1 [L]

Jim

pftodd

10:38 pm on Jun 29, 2009 (gmt 0)

10+ Year Member



Ah, thanks very much.

g1smd

1:25 am on Jun 30, 2009 (gmt 0)

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



It would also be wise to now add a 'redirect' for if anyone tries to access a URL with either 'news.php' or 'content.php' within.