I have written a rewrite rule in the .htaccess
file that will replace any spaces in the URL with .
(dots).
It works fine unless there are numbers in the URL.
RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ . [N,E=NOSPACE:1,DPI]
Any help is greatly appreciated
/search/test test
= Using the above regular expression will work/search/ 123 123
= Not workingP粉9051445142024-01-17 12:35:49
In the regular expression character class, the characters %
, 2
, and 0
are treated as 3 literal characters instead of a single URL-encoded Space (i.e.
). Therefore, any number containing 2
or 0
that also contains or is followed by a space will fail because the regular expression cannot match. RewriteRule
pattern matches the decoded URL path, so there is no need to try to match
at all.
So, you just need to remove
from the rule. For example:
RewriteRule ^([^\s]*)(?:\s)+(.*)$ . [N,E=NOSPACE:1,DPI]