I've heard that you can use mod_rewrite
to clean up your URLs, and basically I'd like to make it so the .php
file extension isn't shown in the URL.
For example, let's say I have the following file structure on a site:
/index.php
/about.php
/contact.php
/css/main.css
/img/animage.jpg
/admin/index.php
/admin/login.php
/admin/admin.php
I would like to make the following basic changes with mod_rewrite:
- When a request is made to the root i.e.
/about
, if a directory is found calledabout
, then it should behave as a directory nomrally does (i.e. load the index.php from the direcotry). - If a directory is not found, it should point to
about.php
- If a request for a
.php
file is made, it should 301 redirect to the filename without the.php
extension. - Only the directories which would actually be viewed directly in the browser should have these URL changes (i.e. the root and the admin directory), therefore css and img should have their URLs unchanged.
How can I make those changes using mod_rewrite
?