Forum Moderators: phranque

Message Too Old, No Replies

rewrites and dashes

pages with dashes in the name cannot be found

         

daneosporin

12:16 am on Dec 28, 2005 (gmt 0)

10+ Year Member



Hi all,
I recently made my site static and I am having a small issue with my rewrite rule.

What I have now is:


RewriteRule ^([0-9]+)-([a-z]+)$ articles.php?url=$2&id=$1 [nc]

This works fine until it gets to an article with a name with dashes in it.

example:
10-mullets
will show content from:
articles.php?url=mullets&id=10

-BUT-
12-rat-tails
will not show:
articles.php?url=rat-tails&id=12

I think this is because I used ([a-z]+) which would only allow letters when I really want to allow letters and symbols. Any suggestions how I can fix this?

jdMorgan

4:09 pm on Dec 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is that you need a unique 'separator' for two functions: 'field-delimiters' for rewriting, and 'keyword-separators'.

You'll need to use a separate character for these two functions, otherwise mod_rewrite will do what you say, and not what you want... :(

You could use '-' for field separators and '+' to replace spaces, just for example. But neither character can then appear in the 'clear text' 'real name' of an item.

Jim

daneosporin

3:46 am on Dec 29, 2005 (gmt 0)

10+ Year Member



Well I solved the problem, also thanks for the response jim. It was a lot easier than I thought and I think my post implied it was harder as well. Basically I just switched the ([a-z]+) to (.*) and now it works perfect.