Rewrite escaped hashtag # #

2019-09-07 01:32发布

问题:

I recently noticed some incoming 404 error hits from URLs with their hashtag escaped.

Correct URL structure: http://example.org/#!/thepage or /index.html#!/thepage

Escaped/ Incorrect URL: http://example.org/%23!/thepage

I tried the following .htaccess rule with little success:

RewriteEngine on
RewriteRule ^%23!/(.*)$ /index.html#!/$1 [NE]

回答1:

Thanks to this answer which pointed me into the right direction: https://webmasters.stackexchange.com/a/76059

Here is the rule that worked for me

RewriteRule ^\x23!/(.*)$ http://www.example.org/index.html#!/$1 [L,R=301,NE]

When using \x it will match escaped characters starting with %