Forum Moderators: phranque

Message Too Old, No Replies

Need to somehow ignore '-' in mod_rewrite

         

The Cricketer

11:06 am on Jun 15, 2005 (gmt 0)

10+ Year Member



I am using urls such as
h ttp://www.mydomain.com/support-widget.htm
in order to use urls like
h ttp://www.mydomain.com/index.php?category=support&filename=widget

I'm using this mod-rewrite in my .htaccess file

RewriteRule (.*)-(.*)\.htm$ /plural/index.php?category=$1&filename=$2

However I'm having problems with urls such as
h ttp://www.mydomain.com/support-widget-blue.htm

Is there a way of:
widget-blue being $2
aswell as
widget being $2 in other situations?

gliff

11:58 am on Jun 15, 2005 (gmt 0)

10+ Year Member



Easiest way? Add a second rewrite rule before your first to catch this special case

RewriteRule (.*)-(.*-.*)\.htm$ /plural/index.php?category=$1&filename=$2

One line, harder to understand later way?

RewriteRule ([^-]+)-(.+)\.htm$ /plural/index.php?category=$1&filename=$2

jdMorgan

2:57 pm on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Avoid the use of ".*" whenever possible. It is the most ambiguous, least-efficient, and most greedy pattern. I recommend the second option offered by gliff above.

Jim