Jump to content
ZeProf2Coding

Delete .php extensions from URL

Recommended Posts

Hello, I want to delete all .php extensions in the url (except index.php).

 

My actual .htaccess file :


### BEGIN - WHMCS managed rules - DO NOT EDIT BETWEEN WHMCS MARKERS ###
<IfModule mod_rewrite.c>
RewriteEngine on

# RewriteBase is set to "/" so rules do not need updating if the
# installation directory is relocated.  It is imperative that
# there is also a RewriteCond rule later that can effectively get
# the actual value by comparison against the request URI.
# 
# If there are _any_ other RewriteBase directives in this file,
# the last entry will take precedence!
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteCond %{REQUEST_URI} !^/index\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

</IfModule>
### END - WHMCS managed rules - DO NOT EDIT BETWEEN WHMCS MARKERS ###

image.thumb.png.f7813de31819c94acdf00038da751c7a.png

But this happens when I try to go on "Espace Client"

Share this post


Link to post
Share on other sites

Try this instead, have tested it also

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

 

Share this post


Link to post
Share on other sites

Try this:

# remove .php from browser address bar via redirect 
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]

# rewrite requests without .php to their real file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

Tested within my dev admin without issue, however, the first one that removes the .php via a redirect will cause pretty much every page load within WHMCS to do a redirect to the version without .php and that can slow down page loads. 

Share this post


Link to post
Share on other sites

image.thumb.png.f02112aa6f41cf4c2b4d58230a91ca59.png

And my file :


### BEGIN - WHMCS managed rules - DO NOT EDIT BETWEEN WHMCS MARKERS ###
<IfModule mod_rewrite.c>
RewriteEngine on

# RewriteBase is set to "/" so rules do not need updating if the
# installation directory is relocated.  It is imperative that
# there is also a RewriteCond rule later that can effectively get
# the actual value by comparison against the request URI.
# 
# If there are _any_ other RewriteBase directives in this file,
# the last entry will take precedence!
RewriteBase /

# Remove .php from browser address bar via redirect 
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]

# Rewrite requests without .php to their real file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
</IfModule>
### END - WHMCS managed rules - DO NOT EDIT BETWEEN WHMCS MARKERS ###

 

Share this post


Link to post
Share on other sites

For some reason, maybe security related, WHMCS requires .php on the file name for at least login.php where other ones worked .  As it may require the same for other files, I would not recommend to remove the .php as it can cause unexpected issues. 

Share this post


Link to post
Share on other sites
15 hours ago, steven99 said:

For some reason, maybe security related, WHMCS requires .php on the file name for at least login.php where other ones worked .  As it may require the same for other files, I would not recommend to remove the .php as it can cause unexpected issues. 

it's probably Friendly URLs related more than security, and i'd go along with the idea that it probably isn't worth attempting to do this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines