Screen Shot for Thumnbails


Conn Warwicker



Portfolio

Scripts and Websites I've made using PHP and MySQL mainly.

Snippets

Code snippets and mini tutorials

Contact

Contact me if you have any questions or queries



Home / Snippets / clean_urls

This section is new and undergoing snippet addition, as of 13/6/11

Clean URLs



Tired of URLs that look like this? http://www.mysite.com?page=index&action=show&eyes=explode

Want URLs like this? http://www.mysite.com/show/love

It's really quite easy to do as long as you have access to the .htaccess file which should be in your public directory (it might be hidden in your file manager).

Simply add this to the .htaccess file:

RewriteEngine On
RewriteBase /

RewriteRule ^([^/\.]+)/?$ index.php?page=$1


What that is telling your web server to do is that everytime someone visits your web url of, e.g. "mysite.com/page1" it will load: "index.php?page=page1", but it won't show that terribly long and ugly URL.

You can then deal with the actual content of the page in the PHP in the "index.php" file by using the $_GET['page'] variable to determine what to show. (It doesn't have to be called "page", it could be whatever you like. You just treat it as you would a normal $_GET[] variable sent in the url).

It's called a Mod ReWrite and you can find more information about them here: Clicky

Leave a Comment


Comment

All fields are required

Your Name


Your Email Address


Your Comment


Human Validation

What animal is this above:






Comments


No Comments Have Been Made