Using mod_rewrite to convert paths with hash characters into query strings

瘦欲@ 提交于 2020-01-01 01:29:47

问题


I have a PHP project where I need to send a hash character (#) within the path of a URL. (http://www.example.com/parameter#23/parameter#67/index.php) I thought that urlencode would allow that, converting the hash to %23

But now I see that even the urlencoded hash forces the browser to treat everything to the right as the URL fragment (or query).

Is there a way to pass a hash through, or do I need to do a character substitution prior to urlencode?

Edit to add (Sep 19 2017):

It turns out that I was asking the wrong question. My issue wasn't with using the hash character within the path (encoding it does work), but in using mod_rewrite to convert it over to a query string. I had failed to re-encode it within the RewriteRule. I'll edit the title to match.

Here is the rewrite rule I was using:

RewriteEngine On
# convert path strings into query strings
RewriteRule "^(.*)/(.*)/hashtags.php"      /hashtags.php?parameter_1=$1&parameter_2=$2 [QSA,L]

As soon as I added the B tag, it worked correctly:

RewriteEngine On
# convert path strings into query strings
RewriteRule "^(.*)/(.*)/hashtags.php"      /hashtags.php?parameter_1=$1&parameter_2=$2 [QSA,L,B]

回答1:


Encode the Hash in the URL with %23

http://twitter.com/home?status=I+believe+in+%23love

"I believe in #love"

URL Encoding Reference: http://www.w3schools.com/tags/ref_urlencode.asp



来源:https://stackoverflow.com/questions/4960513/using-mod-rewrite-to-convert-paths-with-hash-characters-into-query-strings

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