Why does this .htaccess RewriteRule that includes

2019-09-17 20:29发布

Goal: Match URL and rewrite it to a query string.

Problem: Looks like the "#" (and everything after it) in the replacement string is being ignored.

Here's what I have:

RewriteEngine On
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+) web2.html#list?d=$1&n=$2 [L,NE]

This gets to web2.html but the url parameters (d= & n=) are never applied.

The goal is to allow a url like: somewehere.com/55c26838e4b087b032b432c4/1/ to trigger a query like this: somewehere.com/web2#list?d=54668494e4b09ffed41ff167&n=1

1条回答
Deceive 欺骗
2楼-- · 2019-09-17 20:36

Hash-tags are used on client-side only. Try to redirect your request, with R flag specified.

RewriteRule ^([^/]+)/([^/]+) web2.html#list?d=$1&n=$2 [R=301,NE,L]

If that doesn't work fork for you, take a look at HTML5 History API. I think pushState method can help you.

查看更多
登录 后发表回答