Forum Moderators: phranque

Message Too Old, No Replies

I have a problem with htaccess and url

         

Max134

12:54 pm on Jun 7, 2011 (gmt 0)

10+ Year Member



Hello

This is my htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteRule ^([0-9]+)\/$ index.php?logout=$1 [L]


RewriteRule ^news/([0-9]+)-(.*)([0-9]+) detailnews.php?art=$1&name=$2&logout=$3 [L]
RewriteRule ^news/([0-9]+)-(.*) detailnews.php?art=$1&name=$2 [L]
RewriteRule ^news/([0-9]+)/ detailnews.php?art=$1 [L]
RewriteRule ^news/ detailnews.php [L]


And now the problem, that for me it's very weird.

If the url is :http://www.mysite.com/23-this-is-a-new.html

Everything is ok, but if I add a number, like 201 or 2011, the url doesn't works.

For example, that doesn't works:http://www.mysite.com/23-this-is-a-new-2011.html

I don't known what happen ?

Thanks in advance !

David

lucy24

1:53 pm on Jun 7, 2011 (gmt 0)

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



Here:
RewriteRule ^news/([0-9]+)-(.*)([0-9]+) detailnews.php?art=$1&name=$2&logout=$3 [L]

Regular Expressions are "greedy" by default. That means if it sees

23-this-is-a-new-2011

it will read it as

(23-this-is-a-new-201)(1)

Instead, you would need to say

([0-9]+)-((?:\w+-)*)([0-9]+)

(the ?: means "don't capture this bit separately") to force the middle piece to end at the last hyphen.