Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hashtag in apache .htaccess

By using the following .htaccess

RewriteEngine On
RewriteRule ^([0-9]+)/([0-9]+)$ /api/web/index.html#$1/$2 [R=301,NC,L]

When user types the following URL at their browser.

http://localhost:8080/1/2

I'm expecting, Apache will perform internal redirection, and change the displayed URL at browser too (through R=301).

http://localhost:8080/api/web/index.html#1/2

Changing the displayed URL at browser is important. This is to ensure index.html's JavaScript can parse the url correctly.

However, what I really get is

http://localhost:8082/api/web/index.html%231/2

I will get Apache error.

Apache false thought that, I wish to fetch a file named 2 located in directory api/web/index.html%231/

Is there anything I can solve this through modifying .htaccess only?

like image 449
Cheok Yan Cheng Avatar asked Oct 27 '25 09:10

Cheok Yan Cheng


1 Answers

The # is getting encoded as %23. Try using the NE flag in your rule:

RewriteRule ^([0-9]+)/([0-9]+)$ /api/web/index.html#$1/$2 [R=301,NC,L,NE]

the NE flag tells mod_rewrite not to encode the URI.

like image 97
Jon Lin Avatar answered Oct 30 '25 11:10

Jon Lin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!