View Full Version : Encoding only part of a URL
davidrock
03-15-2003, 11:01 PM
Is it possible to encode every character of a url after the main domain name so our directory structure is less apparent? For example I'd like:
http://www.mysite.com/admin/pagename.html
to become:
http://www.mysite.com/%61%64%6D%69%6E%2F%70%61%67%65%6E%61%6D%65%2E%68%74%6D%6C
When I try this, IE says it can't find the page even though the link in the status bar looks absolutely correct when I hover over the encoded link.
Thanks,
David
brothercake
03-15-2003, 11:07 PM
URL encoding is so that you can pass characters which otherwise have a special meaning.
The / character has a special meaning; a URL-encoded / character is just a character; that's why it doesn't work - the browser thinks that everything after your domain name is a single file-name in the root directory.
Of course you can handle that with a CGI script, in order to create a "virtual" directory structure which isn't really there; that's a different thing entirely, and I can provide more info on request.
davidrock
03-15-2003, 11:17 PM
I see what you mean. I tried it by only encoding the actual directory and file names and left the / characters unencoded and it seems to work fine. I think this will work for what we're wanting to do.
Thanks much for your feedback,
David
brothercake
03-16-2003, 12:08 AM
just out of interest - what are you trying to get from this - ie, why do you need to hide your directory structure, and have you considered alternative methods?
davidrock
03-16-2003, 01:20 AM
We are embedding some keywords in our paths to help increase our ranking in search engines. We thought it looked a little funny in the address bar and just wanted to obfuscate it a little.
I guess that brings up another question maybe you know the answer to: Search engine crawlers can understand encoded characters in links without any trouble can't they? Seems like they would follow the same rules in that respect as a standard browser.
Thanks,
David
lord_raven
03-16-2003, 11:58 AM
This might help: Everything after the host (ie /directory/directory/file.php?query=string) goes into the Environmental variable $REQUEST_URI...
Maybe you could do something like:<?
$enc = rawurlencode($REQUEST_URI);
$url = "http://".$HTTP_HOST.$enc;
# Then when you want it back
$dec = rawurldecode($enc);
$url = "http://".$HTTP_HOST.$dec;
?>
I don't know how well this method will work, though... it was just an idea tha popped in to my head... I haven't experimented with it...
brothercake
03-16-2003, 03:07 PM
My opinion is that any "tricks" you use to improve SE rankings are doomed to failure;
at best, they work magnificently for a while - so lots of other people do it, then Google finds out, changes their algorithm and it doesn't work anymore.
but more often, they never work at all and leave you with a pointlessly complicated, obtuse linking convention that makes the *real* business of website popularity (which is - getting people to link to/visit your site because they already know about it, or someone else recommended it) much more difficult - how do you tell someone a URL like that over the phone? or write it down?
IMHO - you're creating a nightmare for yourself which will ultimately give you no benefit. At the very least, don't URL encode the characters; live with how strange it looks.
IMHO ...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.