Aber LINKS Website – URL Redirecting From “/news.php” to “/news” With .htaccess

Had an Idea – well I have always wanted to be able to type www.aber-links.co.uk/contact rather than /contact.php to get to the contact page – and the only idea I had myself was creating a directory called /contact with an index.php file in there, either that or a redirection to the actual /contact.php. I thought surely there must be a better way, and after a little searching online and reading – I found a way.

If you have a site, in the root directory (or /public_html) there should be a file called “.htaccess”. This file is a configuration file for web servers, so you can give it some rules. For example, mine has a line:

ErrorDocument 404 /notfound.php

This redirects the user to the page “notfound.php” if they get a 404 error (page not found). To redirect the user from an input like “www.aber-links.co.uk/news” to the /news.php page, you need the following lines:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.php [L]

If your site is .html files, change the .php to .html or .htm – whatever you use.

news URL example

I read this article to learn about what to put: http://www.webmasterworld.com/apache/3715021.htm

Matt