Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite

replace spaces

         

gosman

7:55 pm on Feb 9, 2006 (gmt 0)

10+ Year Member



I have the follwoing .htaccess which works fine.

Options +FollowSymlinks
RewriteEngine On

rewriterule ^product/(.*).htm$ product.php?PID1=$1

[mysite...] translates to [mysite...]

My problem is sometimes the product will have a space in it.

Eaxmple [mysite...] widget.htm

I dont want to use %20 when a space appears in the product. Instead I want to use a - but then have the rewrite rule replace the - with %20.

So for example the following [mysite...] would translate to [mysite...]

I would appreciate if anybody can advise on how this can be done.

extras

9:16 pm on Feb 9, 2006 (gmt 0)

10+ Year Member



I think you should sinply use + instad of -.
Normally, + will be decoded back to a space, just like %20.

You can replace - with %20 using RewriteRule.
It's easy if you know the maximum number of - in the URL.
But it can complicate your life and make debugging difficult.

If you insist, add this line:
rewriterule ^product/([^-]+)-(.*).htm$ product/$1\ $2.html [L]

before this rule:
rewriterule ^product/(.*).htm$ product.php?PID1=$1 [L]

and it should translate at last several hyphens.

If it fails, you may want to try this:
rewriterule ^product/([^-]+)-(.*).htm$ product/$1%20$2.html [L,NE]