0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

ouch. Thanks, but that breaks my links locally, can I add a .htaccess file to my local folder?
If you're running Apache, sure.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.