Page 1 of 1

mask URL

Posted: Fri Jul 03, 2009 9:54 pm
by podarum
Anyone know how I can mask an URL from let's say from http://www.aaa.com/access.php to just http://www.aaa.com ? Don't want to use frames or $_SERVER, was thinking more like .htaccess or something else. Thanks

Re: mask URL

Posted: Fri Jul 03, 2009 10:38 pm
by JAB Creations
Apache .htaccess

Code: Select all

<ifmodule mod_rewrite.c>
 RewriteEngine on
 RewriteRule ^(exception_file.php|exception_folder/) - [L]
 RewriteRule !\.(css|cur|exe|gif|gz|html|h3m|ico|jpg|js|mov|mp3|mp4|msi|pdf|pl|png|rar|swf|ttf|txt|wmv|xhtml|xml|xpi|zip)$ index.php
</ifmodule>
This snippet will redirect all requests to be handled by index.php. You'll likely end up working extensively on a CMS class module and $_SERVER['REQUEST_URI'].

Think of this as not redirecting access from one file to another, but determining what path was requested and then generating content based on the requested path.

Re: mask URL

Posted: Fri Jul 03, 2009 10:47 pm
by podarum
Thanks Jab,
So if I get this straight if I copy this code in my .htaccess, then every page will show up as http://www.aaa.ccom, rather than just the only one I want http://www.aaa.com/access.php ? or am I reading it wrong...

Re: mask URL

Posted: Fri Jul 03, 2009 11:46 pm
by JAB Creations
No...

Every file you request (e.g. /, /example1, example2, example3) will be handled by the file specified in the .htaccess. So if you put this in your site's root .htaccess file as then what you can effectively do is program your site to generate any page at any URL. You're not masking, you're creating.

Set this up locally for testing and then request some non-existent URL's. Any content on index.php will be seen on any page you request regardless of it's URL.

That is where $_SERVER['REQUEST_URI'] comes in. You don't have to serve a static copy of index.php...because that file itself can decide what content you use. You'll want to get comfortable with blowing stuff up too while you're at it. No put the TNT down, I mean using PHP's explode function. Explode with '/' and then reference those pieces of pizza as demonstrated on php.net. From that you determine what section, area, page, etc has been requested. From there you determine the HTTP headers (200 found, 403 forbidden, 404 not found, etc) and serve content based on what page was requested in conjunction with how you setup the anchors on the website itself.

It's an engaging method of setting up a site though it's extremely powerful and once you get used to it you'll wonder how the heck you ever did this stuff before. :)