Home >Backend Development >PHP Tutorial >How Can I Hide File Extensions (like .php) from My Website\'s URL?
Hiding File Extensions in Website Addresses
When designing a website, you may prefer to conceal file extensions like .php or .jsp from the address bar for aesthetic reasons. This article provides a comprehensive solution to achieve this effect, based on an actual question and answer.
The Question:
A website developer sought a way to remove the file extension from their website address. They wanted the URL to appear as http://something.example/profile, rather than http://something.example/profile.php. This is commonly seen in websites like Stack Overflow.
The Solution:
To address this issue, you can create an .htaccess file in the root directory of your website. For instance, in /home/domains/domain.example/htdocs/, add an .htaccess file with the following content:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ .php
Explanation:
By implementing this solution, your website address will appear without file extensions, providing a more polished and professional look.
The above is the detailed content of How Can I Hide File Extensions (like .php) from My Website\'s URL?. For more information, please follow other related articles on the PHP Chinese website!