Moussa Posted March 21, 2017 Share Posted March 21, 2017 How to remove file extensions Hello all i made this post to show you how to remove file extensions like [ www.example.com/index.php ] now i will show you how to remove .php in the end file to be [ www.example.com/index ] it will help your clients to open your website now follow this steps : open new Notepad save this code in new notepade RewriteEngine On # Unless directory, remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/$ https://yourwebsitelink.com/$1 [R=301,L] # Redirect external .php requests to extensionless url RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ RewriteRule ^(.+)\.php$ https://yourwebsitelink.com/$1 [R=301,L] # Resolve .php file for extensionless php urls RewriteRule ^([^/.]+)$ $1.php [L] Now change https://yourwebsitelink.com with your website link there is two to changeing Save the Notepade with name .htaccess and uploade with your website files and see what will happend Quote Link to comment Share on other sites More sharing options...
Anyx Posted October 4, 2018 Share Posted October 4, 2018 On 21/3/2017 at 9:21 PM, Moussa said: How to remove file extensions Hello all i made this post to show you how to remove file extensions like [ www.example.com/index.php ] now i will show you how to remove .php in the end file to be [ www.example.com/index ] it will help your clients to open your website now follow this steps : open new Notepad save this code in new notepade RewriteEngine On # Unless directory, remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/$ https://yourwebsitelink.com/$1 [R=301,L] # Redirect external .php requests to extensionless url RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ RewriteRule ^(.+)\.php$ https://yourwebsitelink.com/$1 [R=301,L] # Resolve .php file for extensionless php urls RewriteRule ^([^/.]+)$ $1.php [L] Now change https://yourwebsitelink.com with your website link there is two to changeing Save the Notepade with name .htaccess and uploade with your website files and see what will happend Thanks for this code! I assume it works with HTML also, I will definitely give it a try! Quote Link to comment Share on other sites More sharing options...
xpde Posted October 4, 2018 Share Posted October 4, 2018 5 hours ago, PCTipsGR said: Thanks for this code! I assume it works with HTML also, I will definitely give it a try! That code is specifically for removing PHP. To remove the .html extension, just rewrite the code a little bit RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html [NC,L] Quote Link to comment Share on other sites More sharing options...
Anyx Posted October 5, 2018 Share Posted October 5, 2018 13 hours ago, xpde said: That code is specifically for removing PHP. To remove the .html extension, just rewrite the code a little bit RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html [NC,L] Thanks for posting that here! I know your time is valuable and so I thank you for giving time to see this post and answer. Quote Link to comment Share on other sites More sharing options...
xpde Posted October 8, 2018 Share Posted October 8, 2018 On 10/5/2018 at 9:41 AM, PCTipsGR said: Thanks for posting that here! I know your time is valuable and so I thank you for giving time to see this post and answer. Nah, you're good man. I'm just trying to help another person out. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.