Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top