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

Discussion in 'Web Development' started by CabCon, Apr 28, 2016.

  1. CabCon

    CabCon Head Administrator Staff Member Head Staff Team

    4,068
    2,641
    403
    Credits:
    188,474
    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.
     

    Attached Files:

    Gentle and Procyon like this.
  2. Harry

    Harry Software Engineer Premium Member

    1,201
    974
    398
    Credits:
    5,936
    <3 Thanks babe. Might try this on my school projects to look more 1337
     
    Syndicate and CabCon like this.
  3. Gentle

    Gentle Guest

    Credits:
    0
    Nice tutorial <3
     
    CabCon likes this.
  4. CabCon

    CabCon Head Administrator Staff Member Head Staff Team

    4,068
    2,641
    403
    Credits:
    188,474
    Thank you :tonguewink:
     
    Gentle likes this.
  5. Tusta

    Tusta Head Member Donator

    20
    11
    14
    Credits:
    3,242
    Thanks Its perfect for me! :smile:
     
    CabCon likes this.
  6. CabCon

    CabCon Head Administrator Staff Member Head Staff Team

    4,068
    2,641
    403
    Credits:
    188,474
    Thank you, yes It makes your site look better. :smile:
     
    Tusta likes this.
  7. Lucifer

    Lucifer Moderator Staff Member

    806
    550
    303
    Credits:
    4,547
    This will be nice when I start to create my modding website from scratch :grinning:
     
    CabCon and Tusta like this.
  8. CabCon

    CabCon Head Administrator Staff Member Head Staff Team

    4,068
    2,641
    403
    Credits:
    188,474
    If you're using wp or a forum software it's standard built in.
     
    Lucifer likes this.
  9. Lucifer

    Lucifer Moderator Staff Member

    806
    550
    303
    Credits:
    4,547
    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 likes this.
  10. CabCon

    CabCon Head Administrator Staff Member Head Staff Team

    4,068
    2,641
    403
    Credits:
    188,474
    That's awesome! :smile: Let me know when you need some testers :smile:
     
    Lucifer likes this.
  11. Lucifer

    Lucifer Moderator Staff Member

    806
    550
    303
    Credits:
    4,547
    sure will
     
    CabCon likes this.

Share This Page