简体   繁体   中英

How to hide PHP extension redirecting to same URL without the extension in HTACCESS

I have a website with multiple *.php pages : { index.php, products.php, contact.php ... }

I would like to use URL-friendly URLs, which will be of kind: { /, products, contact ... }

But I also want that if the user writes the complete URL, for example, www.example.com/contact.php, she will be redirected to www.example.com/contact, and the corresponding PHP file (contact.php) be executed. She never will have contact.php in the URL because of the redirection, unless she hits "stop" very fast.

How can I achieve this? I think is some kind of redirect and also let APACHE know that those redirects have the "hidden" extension ".php".

In your .htaccess file

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM