Forum Moderators: phranque
On my site, all urls go through one php file. My current rewrite is:
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NE]
This results in the %23 turning into a # and dissapearing into /dev/null
The variables that PHP gets in the end (after rewrite) are:
REDIRECT_QUERY_STRING q=index/alphabetical#/
REDIRECT_URL /fms/index/alphabetical#/
QUERY_STRING q=index/alphabetical
REQUEST_URI /fms/index/alphabetical%23/
But I really would like the QUERY_STRING to be is:
q=index/alphabetical#/
I tried to apply ideas from:
[webmasterworld.com...]
[webmasterworld.com...]
hence the ,NE] in the inital rule.
Any help would be a godsend.
First, you are not free to place any characters you choose in any part of a URL; The HTTP protocol specifies restrictions [faqs.org] on which characters can appear in which parts of a URL. The "#" character, being defined as as an on-page local HTML anchor, is never handled by servers; It is used soley within the client to identify sub-parts of a single HTML docuement. Therefore, Apache drops it, and anything following it in a URL. (Note that a query string is data appended to a URL to be passed to the resource identified by that URL, and is therefore not considered to be part of the URL itself. This clarifies the preceding sentence, and also explains the 'separate' query string handling in Apache.)
Second, parts of the URL have meaning to Apache, and will be handled according to that interpretation.
Bottom line is that an unescaped "#" cannot be sent through HTTP (which is why your browser escapes it to "%23"), and -apparently- also cannot appear in a query string. So, there's nothing you can do to easily 'force' this.
However, a very slight change in approach may clear the way for you: Simply delete any query string manipulation from your RewriteRule, and let the script extract the parameters itself, since you've shown that they are still present in the server variables accessible by the script.
Another solution would be to use a different character -- One that Apache does not see as being a 'local HTML anchor' like "#".
Jim