Forum Moderators: phranque

Message Too Old, No Replies

Mod_Rewrite Problem With "="'s

What do I put?

         

wfernley

6:30 pm on Jan 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone. I have an easy question. I have this in my .htaccess file:

#change products id's to actual keywords in the address bar
RewriteRule ^([0-9A-Za-z]+)/([0-9A-Za-z]+)/([0-9A-Za-z]+)/index.html itemdetails.php?products_sku=$3

Basically it changes this /computer/cables/skunumber/index.html into itemdetails.php?products_sku=skunumber. The problem I am having though is that some of my skus have a dash in them. An exmaple could be PS2-6foot.

I was curious how to edit ([0-9A-Za-z]+) to include a dash when there is one present. I guess it would be considered a special character.

Also another problem I might as well mention that I am having is with custom error pages. I tried using the ErrorDocument 404 /error.php line in my .htaccess but for some reason this doesn't work for me. It says the file cannot be found even though its there. What could the problem be? I don't have access to the Apache configuration files so I can't look in there.

Thanks for your help.

Wes

wfernley

9:30 pm on Jan 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry I noticed I put "="'s in the Title and it should be "-"'s.

sorry about that,

Wes

jdMorgan

11:14 pm on Jan 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Simply add the hyphen to the grouped alternates at the beginning: [-0-9A-Za-z]+
Alternately, you can accept *any* characters up to the next "/" by using [^/]+ which translates to "one or more characters not equal to a slash."

See the regular-expressions tutorial cited in our forum charter [webmasterworld.com] for more info.

Jim