Removing File Extension from Website Address
In the realm of web design, it's often desirable to conceal file extensions from URLs for aesthetic and accessibility reasons. For instance, instead of displaying an address like http://something.example/profile.php, you may prefer a more succinct format like http://something.example/profile.
To achieve this, you can employ the following approach:
In the root directory of your website (e.g., /home/domains/domain.example/htdocs), create an .htaccess file. This file is responsible for configuring Apache's handling of HTTP requests.
Within the .htaccess file, add the following code snippet:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ .php
This code performs the following actions:
This setup effectively hides the .php extension from the URL while still allowing Apache to process PHP scripts as usual.
For further details on the functionality of this code, refer to the mod_rewrite guide and reference documentation.
The above is the detailed content of How Can I Remove File Extensions from My Website URLs?. For more information, please follow other related articles on the PHP Chinese website!