Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using mod_rewrite to convert paths with hash characters into query strings

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] 
like image 376
Mark Avatar asked Feb 10 '11 17:02

Mark


1 Answers

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

like image 181
sparkyspider Avatar answered Oct 12 '22 12:10

sparkyspider