问题
I have the following url (there are a few like these):
mysite.co.uk/productdetails/408/20/Casio%C2%A0CTK1100/
and I want to rewrite it to:
mysite.co.uk/Casio-CTK1100-in-Black/393
The problem is this funny %C2%A0 now I have other links with multiple spaces in there and they are rewritten as follows:
# take care of %C2%A0
RewriteRule ^(.+)\xc2\xa0(.+)$ $1-$2 [L,NE]
# executes **repeatedly** as long as there are more than 1 spaces in URI
RewriteRule "^(\S*) +(\S* .*)$" $1-$2 [L,NE]
RewriteRule "^productdetails/617/6/(\S*) (\S*?)/?$" /$1-$2/302 [L,R=302,NE] (is just and example of a url with more than 1 space)
This works prefect, however when the url only has one space in it like the one shown above it will not work. I will need to keep the above rule in my .htaccess file to be able to rewrite the urls with multiple space.
Any help welcome
回答1:
You can have it like this:
# take care of %C2%A0
RewriteRule ^(.+)\xc2\xa0(.+)$ $1-$2 [L,NE]
# executes **repeatedly** as long as there are more than 1 spaces in URI
RewriteRule "^(\S*) +(\S* .*)$" $1-$2 [L,NE]
RewriteRule "^productdetails/617/6/(\S*) (\S*?)/?$" /$1-$2/302 [L,R=302,NE]
RewriteRule "^productdetails/408/20/(\S+?)/?$" /$1-in-Black/393 [L,R=302,NE]
来源:https://stackoverflow.com/questions/25865713/rewrite-a-url-with-one-non-breaking-space-in-htaccess