Question

(This seems like it should be one of the mostly commonly and easiest addressed questions on the web, since most websites have "pretty" or "clean" urls. But in all my searches, it's proven to be one of the most complex.)

In the simplest form, I would like be able to enter example.com/about into the url bar and have the server return the file example.com/about.php. As it is, I have to enter or link to example.com/about.php, which is not SEO or user friendly. This isn't about complex strings--the file could just as easily be example.com/about.html.

I have some code I'm attempting to use with an .htaccess file, but it seems to do nothing:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-z]+)/$ /$1.php

I know that the .htaccess file is working, because the 404 redirect I have set up (which appears in the .htacces doc below the code I've included here) is functioning properly, especially when I'm trying access example.com/about and I get my 404 page.

Thanks for your help!

Was it helpful?

Solution

Your last rule is designed to match http://example.com/about/ . I think what you want is

RewriteRule ^([a-z]+)$ $1.php
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top