RewriteRule and the number sign "#"

I am trying to make a friendly URL through a RewriteRule , but it continues to ignore # as part of the variable value.
The line on .htaccess is as simple as this

 RewriteRule ^key/(.+)/$ index.php?key=$1 

and requested URL

 http://www.example.com/key/c%23/ 

but I get c as get variable, not c%23 .

What exactly am I doing wrong?

+6
source share
3 answers

Finally, after some digging, I managed to take it off.

For RewriteRule, you just need flag B to remove non-alphanumeric characters like #

  RewriteRule ^ key /(.+)/$ index.php? Key = $ 1 [B] 
+4
source

%23 is a hash ( # ) symbol, so it (and nothing after it) is not actually parsed by mod_rewrite. The actual URL is therefore http://www.foo.com/key/c , without %23 . However, other barcodes work fine.

0
source

%23 is the hash mark (#). I assume that the browser interprets the hash as an anchor and does not pass it to the server. For example, if you are a user http://www.foo.com/key/c%20/ , you will get "c [space]".

0
source

Source: https://habr.com/ru/post/888669/


All Articles