vinylDeveloper
vinylDeveloper

Reputation: 707

Can't drop .php extension from files in .htaccess

I'm trying to drop to .php extension on my files in the url. It seems like it should be really easy, but I can't get it to work.

For Example, If I link to a page in my site.

<a href="/admin_login.php">admin</a>

the url reads like this

www.domain.com/admin_login.php

I want it to read like this

http://www.domain.com/admin-login

In my .htaccess file I have this

RewriteEngine ON
RewriteRule ^([^/.]+)$ $1.php [L]

also tried this

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php [R=301,L]

What am I doing wrong?

Please don't tell me I have to go through my site and change every link to drop the .php extension.

Upvotes: 0

Views: 50

Answers (1)

ceejayoz
ceejayoz

Reputation: 180004

Please don't tell me I have to go through my site and change every link to drop the .php extension.

You do. Your rewrite rules tell the webserver to send <anything> to <anything>.php, but that won't magically adjust all the links in your code to use those new alternate URLs.

Upvotes: 1

Related Questions