htaccess: how to rewrite to clean urls and redirect old urls to the new clean ones?

Posted by Sebastian on Server Fault See other posts from Server Fault or by Sebastian
Published on 2011-12-28T11:26:49Z Indexed on 2013/06/28 16:24 UTC
Read the original article Hit count: 221

Filed under:
|
|
|
|

With htaccess I'm trying to make my sites urls clean. I use very basic urls like: www.mysite.com/pagename.php ("pagename" is variable).

I want www.mysite.com/pagename to display the content of /pagename.php
So this is in my htaccess-file now:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

But I also want my old urls (/pagename.php), when called, to be rewritten to www.mysite.com/pagename

How to do this? I can't figure it out (get loops all the time)...

Thanks in advance!

© Server Fault or respective owner

Related posts about apache2

Related posts about .htaccess