1

So the jist of this is, I have a file:

search.php

When I goto:

search.php?search=%23HashTag

The search returns: #HashTag

But when I use my .htaccess method:

/search/%23HashTag

Nothing is returned. And i've tested by putting the number sign later in the search and it returns upto that point.

This is what I have:

RewriteRule ^search/([^\.]+)$ search.php?search=$1 [NE,L]

What am I doing wrong..?

2 Answers 2

2

Change your flags to [NE,B,L].

http://httpd.apache.org/docs/current/rewrite/flags.html#flag_b

mod_rewrite unescapes the url before applying transformations. I'm not sure why it loses anything after the hash (maybe it re-interprets it as a url, and discards the fragment?). In any case, [B] re-escapes the url before running it through the rewrite rule.

Sign up to request clarification or add additional context in comments.

Comments

0

Does replacing it with \%23 work ok?

(Clarity: Opposed to writing the # in the .htaccess file)

2 Comments

It actually just changes the \ to a forward slash
Just moved to a FreeBSD apache server, and I notice it doesn't work on that distro.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.