38430

How do I remove the '.php' extension from URLs?

Question:

This is where the PHP files are:

ts1.WEBSITENAMEHERE.biz/cp/

The .htaccess file is also in this folder. I want to remove the '.php' from 'FILENAME.PHP'.

This is my current '.htaccess' file:

Options +FollowSymlinks RewriteEngine on RewriteBase /cp RewriteRule ^(.*)/$ $1.php

But it is not working. Why is this?

Answer1:

RewriteEngine on RewriteBase /cp/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !\.php$ RewriteRule .* $0.php [L]

Answer2:

Create a .htaccess file in the DocumentRoot dir. Add the following code in that file...

############## RewriteEngine On RewriteCond %{REQUEST_URI} !^(.*)\.(.*)$ RewriteRule ^(.*)$ %{REQUEST_URI}.php [R] #############

mod_rewrite should be enabled for this to work.

Answer3:

Options +FollowSymlinks RewriteEngine on RewriteBase /cp RewriteRule ^(.*) $1.php

I use this checker: <a href="http://htaccess.madewithlove.be" rel="nofollow">http://htaccess.madewithlove.be</a>

Recommend

  • Requests to existing files execute index.php
  • htaccess *.php to *.html object not found error
  • htaccess - IP canonicalization to HTTPS
  • .htaccess redirect ~ [fake-subdomain.domain.com/*] to [domain.com/*]
  • Get rid of Index.php in CodeIgniter URLs
  • Codeigniter 2.1.4 installation in sub directory
  • Dart HTTP server and Futures
  • Haskell permutation library function - please clarify?
  • Using Regex to split XML string before and after match
  • RewriteCond and rewriteRule to redirect depending on the domain
  • Help with mod_rewrite
  • help('modules') crashing? Not sure how to fix
  • Refactoring advice: maps to POJOs
  • Regex for URL rewrite with optional query string parameters
  • msbuild create itemgroup from property group
  • List images(01.png) and descriptions(01.txt) from directory
  • Apache RewriteRule redirection with url encoded
  • how to upload multiple files in c# windows application
  • Use of this Javascript
  • Refering to the class itself from within a class mehod in Objective C
  • How to install a .deb file on a jailbroken iphone programmatically?
  • Handling un-mapped Rest path
  • Why is an OPTIONS request sent to the server?
  • Spring security and special characters
  • Deleting and Updating values from a cusrsor adapter
  • Modifying destination and filename of gulp-svg-sprite
  • Perl system calls when running as another user using sudo
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • To display the title for the current loaction in map in iphone
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Matrix multiplication with MKL
  • PHP: When would you need the self:: keyword?
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • Acquiring multiple attributes from .xml file in c#
  • Hits per day in Google Big Query
  • File not found error Google Drive API
  • reshape alternating columns in less time and using less memory
  • Converting MP3 duration time
  • How can I use threading to 'tick' a timer to be accessed by other threads?