使用mod_rewrite将带有散列字符的路径转换为查询字符串 [英] Using mod_rewrite to convert paths with hash characters into query strings
问题描述
我有一个PHP项目,需要在URL的路径中发送哈希字符(#)。 ( http://www.example.com/parameter#23/parameter #67 / index.php )我认为,urlencode会允许,将散列转换为%23
但现在我看到即使是urlencoded散列力浏览器将所有东西都作为URL片段(或查询)来处理。
有没有办法通过散列,或者我需要做一个字符替换urlencode之前?
修改即可添加(2017年9月19日):
>事实证明,我问的是错误的问题。我的问题不是在路径中使用散列字符(对其进行编码),而是使用mod_rewrite将其转换为查询字符串。我没有在RewriteRule中重新编码它。我将编辑标题以匹配。以下是我正在使用的重写规则:
RewriteEngine On
#将路径字符串转换为查询字符串
RewriteRule^(。*)/(。*)/ hashtags.php/hashtags.php?parameter_1=$1& ; amp; parameter_2 = $ 2 [QSA,L]
只要我添加B标记,正确工作:
$ b $ pre $ RewriteEngine On
#将路径字符串转换为查询字符串
RewriteRule^(。* )/(。*)/ hashtags.php/hashtags.php?parameter_1=$1&parameter_2=$2 [QSA,L,B]
使用%23编码哈希中的URL
http://twitter.com/home?status=I+believe+in+%23love
我相信#love
URL编码参考: http://www.w3schools.com/tags/ref_urlencode.asp
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]
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
这篇关于使用mod_rewrite将带有散列字符的路径转换为查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!