Report this

What is the reason for this report?

Hide .php dont work

Posted on April 9, 2017

Hello, I have a question, I am trying to hide .php with .htaccess in Centos 7 but it is not working. Would you help me?

My code .htaccess:

Options +MultiViews

Run Php without filename extension

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php

Return 404 if original request is .php

RewriteCond %{THE_REQUEST} “^[^ ]* .?.php[? ].$” RewriteRule .* - [L,R=404]



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Did you check the logs? Did you load mod_rewrite? Did you configure AllowOverride?

@marcelolop3s

It’d be far better to handle this using a router and simply point all requests to your index.php file for processing (which is what WordPress and other CMS’s do). Using a router of sorts would provide you with far more utility and allow for more options when it comes to processing requests.

If you’re stuck with .htaccess, either because you’re not able to use a router, or code your own, then you could try using:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]

or

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.