Home >Backend Development >PHP Tutorial >How Can I Remove File Extensions from Website URLs Using .htaccess?
Removing File Extensions from Website Addresses
In web design, removing file extensions can enhance the aesthetic appeal of URLs by concealing the programming language used behind the scenes. To achieve this, you can utilize the following steps:
Step 1: Create an .htaccess File
Navigate to the root folder of your website and create a file named ".htaccess" (ensure it starts with a period).
Step 2: Add the Rewrite Rules
Open the .htaccess file and insert the following rewrite rules:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ .php
Explanation of Rewrite Rules:
Example:
If a request is made for "http://something.example/profile," the rewrite rule will automatically redirect it to "http://something.example/profile.php," while the URL displayed in the address bar will remain "http://something.example/profile."
Additional Information:
The above is the detailed content of How Can I Remove File Extensions from Website URLs Using .htaccess?. For more information, please follow other related articles on the PHP Chinese website!