How to Conceal .php Extension Using .htaccess
Removing the .php file extension can be a useful technique for maintaining website cleanliness and enhancing user experience. However, achieving this can be challenging.
Detailed Explanation:
Your code attempts to rewrite URLs within the "folder" directory, redirecting them to their .php counterparts. However, your code seems to be incorrect.
Solution:
The following code resolves this issue effectively:
RewriteEngine On # Unless directory, remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/$ http://example.com/folder/ [R=301,L] # Redirect external .php requests to extensionless URL RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ RewriteRule ^(.+)\.php$ http://example.com/folder/ [R=301,L] # Resolve .php file for extensionless PHP URLs RewriteRule ^([^/.]+)$ .php [L]
For further guidance, refer to the referenced question's solution: https://stackoverflow.com/questions/14425845/remove-php-extension-with-htaccess.
The above is the detailed content of How Can I Use .htaccess to Remove the .php Extension From My Website URLs?. For more information, please follow other related articles on the PHP Chinese website!