.htaccess does not recognize numbers in regular expressions, please rewrite
P粉651109397
P粉651109397 2024-01-16 17:48:10
0
1
459

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 working

P粉651109397
P粉651109397

reply all(1)
P粉905144514

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]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!