search

Home  >  Q&A  >  body text

.htaccess does not recognize numbers in regular expressions, please rewrite

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

P粉651109397P粉651109397313 days ago481

reply all(1)I'll reply

  • P粉905144514

    P粉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]

    reply
    0
  • Cancelreply