How to remove File Extentions from URLs on your website. | Working with .htaccess

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
4,998
Reaction score
2,918
Points
1,053
Hello,
today I will simply share this with you. How to remove file extentions from you're website.

To remove file extentions from urls you need to create a .htaccess file in your root folder of your server.


Code:
www.test.com/index.html -> www.test.com/index

To remove the .html you need to copy this code into the file. (You can also use it with any other file extention e.g. .php)
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]


Code:
www.test.com/index -> www.test.com

If also want to remove the index from your index page of your site, copy this code below.
Code:
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]

RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]


You can of course use booth together and simple download our template file below.
Thanks for reading, @CabCon.
 

Attachments

  • .htaccess
    267 bytes · Views: 355

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
4,998
Reaction score
2,918
Points
1,053
This will be nice when I start to create my modding website from scratch :grinning:
If you're using wp or a forum software it's standard built in.
 

Lucifer

Veteran
Messages
771
Reaction score
502
Points
878
If you're using wp or a forum software it's standard built in.
i am not using a forum software i am building it from scratch pure code :tonguewink: i wanna improve my coding skills so i thought i would challenge myself
 

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
4,998
Reaction score
2,918
Points
1,053
i am not using a forum software i am building it from scratch pure code :tonguewink: i wanna improve my coding skills so i thought i would challenge myself
That's awesome! :smile: Let me know when you need some testers :smile:
 
Top