Why does this .htaccess RewriteRule that includes a '#' fail?

▼魔方 西西 提交于 2020-01-06 07:07:19

问题


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:


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.



来源:https://stackoverflow.com/questions/31859377/why-does-this-htaccess-rewriterule-that-includes-a-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!