Problem with hyphens

New to mod_rewrite? This is a good place to start.

Problem with hyphens

Postby Pistons » Tue Nov 17, 2009 3:24 am

Hi

In many projects I have used the following rule for a clean url.

RewriteRule ^([a-zA-Z0-9\-]+)/news/([0-9]+)-([a-zA-Z0-9\-\+]+)([/])?$ content/news/item.php?lang=$1&id=$2 [QSA,L]

This would produce: www.mydomain.com/en/news/1-subject-of-my-newsitem/

This used to work fine, untill I moved to another webhost.
The problem lies within the last part of the rule.

For example, this would still work: www.mydomain.com/en/news/1-subject/
This on the other hand, does not: www.mydomain.com/en/news/1-subject-of-my-newsitem/

If the last part (the subject) contains hyphens, it results in an 404 error.


Is there a way I could fix this ?
Pistons
 
Posts: 4
Joined: Tue Nov 18, 2008 9:11 am

Postby Pistons » Tue Nov 17, 2009 7:37 am

I've made some changes to the rule and it seems to work now.

RewriteRule ^([a-zA-Z0-9\-]+)/news/([0-9]+)-([^/]*)([/])?$ content/news/item.php?lang=$1&id=$2 [QSA,L]
Pistons
 
Posts: 4
Joined: Tue Nov 18, 2008 9:11 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 4 guests

cron