homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Escape a pound sign (#) in .htaccess

 4:59 pm on Dec 2, 2009 (gmt 0)


I've looked for it over google but couldn't find any answer...
I've read that it's not a legal character for URLs and all, so it might not be possible to escape a #, but maybe someone knows how to do it.

I actually need it to rewrite some URLs on a website that uses swfaddress. Which means that there is a # sign that I need to escape, but I have no idea how to do this (and I'm clearly no expert on .htaccess or Apache either...).

Anyone has an idea?

Thanks in advance!



 6:13 pm on Dec 2, 2009 (gmt 0)

Do you really have a known problem? Probably not, because any modern browser, when requesting a link with a reserved character in it, is going to encode that character automatically... So this will already be taken care on the client side.

Besides which, if any client ever sent an un-escaped reserved character, then your server would reject the request with a 400 error before .htaccess was ever invoked...

If that's not entirely clear, then be aware that .htaccess runs as an incoming client HTTP request is received by your server, and before any content handlers are invoked or any content is served. That is, .htaccess acts on incoming URL requests, and does not perform any kind of filtering or modification operations on the output of your page content.

I'd be looking for 'real' problems, instead of 'maybe' problems. For example, do you force canonicalization of your domain name and URLs? That's a very real problem if not... and there are lots of previous threads here on that subject. :)



 6:26 pm on Dec 2, 2009 (gmt 0)

hum... I'm not sure you understood my problem correctly (or if you did, then maybe, I didn't understand your answer correctly). But my eplanations were probably not that accurate as well, so sorry if I couldn't explain my problem clearly.

What I want to do precisely, is to create a subdomain that would point to an address that contains a # in it (because of the swfaddress).
For example, part1.domain.com would have to point to something like www.domain.com/#/folder1/folder2/part1/...


 6:58 pm on Dec 2, 2009 (gmt 0)

In that case, you don't have a problem, because you are taking an incoming URL request of "part1.example.com" and mapping it to the filesystem path of /#/folder1/folder2/part1/

This is called an internal rewrite -- a URL-to-filepath mapping function. It is not an HTTP redirect and therefore does not involve any transmission of the filepath as a URL, so HTTP URL-encoding requirements do not apply. Only the rules and restrictions of the server operating system's filesystem need to be considered.



 7:15 pm on Dec 2, 2009 (gmt 0)

Ok, but how should I put it in my .htaccess then? I'm sorry but I'm really a novice...

What I tried didn't work:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.example.com
RewriteCond %{HTTP_HOST} ^part1.example.com
RewriteRule ^$ /#/folder1/folder2/part1/[

Without the '#' (just normal folders redirection) works, but as soon as I use the '#', I have a 500 Internal Server Error.
I guess this is normal since the # is normally interpreted as a comment mark, no?
I tried to use \# but it didn't work either...


 8:11 pm on Dec 2, 2009 (gmt 0)

Note that there's a spurious "[" at the end of yur code. If it was meant to be there to enclose a RewriteRule flag, then that flag is missing (there's also a space required before the bracket denoting rule flags, which may also be missing).

As for escaping the "#", try \%23 with an [NE,L] flag on the rule.

Also, look at your server error log file; If "#" isn't allowed by your server filesystem, it should say so. And if there's some other problem, then it will say so... the error logs are generally quite useful.



 8:21 pm on Dec 2, 2009 (gmt 0)

For the "[" at the end of the code, it was just a mistake while pasting it. But thanks for the corrections.

I just tried it and the \%23 works! Thanks a lot for your time, patience and useful advices!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved