Jump to content
Xbox Modders Community
Ryan1523059446

.htaccess Tutorial #1 | Hide File Extensions On Your Site

Recommended Posts

htaccess-files-for-the-rest-of-us-1.jpg

 

The .htaccess file can be very powerful and a file which you may want to take advantage of when making a website, the .htaccess can do alot of wonders which may blow your mind, so in these tutorials i will be teaching you some of the stuff that i have learnt about the .htaccess.

 

.htaccess Tutorial #1 - Hide File Extensions On Your Site:

There's alot of websites that you see on the web that do not have a file extension at the end of their file name, now one way inwhich you can do this is by using separate directories for each file that you want to hide the extension and then using .htaccess redirect to that certain file. However i'm going to be showing you a better way and a way which will save you move space on your web server.

 

The Coding!

 

 

All you want to use is this code:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.fileextension -£
RewriteRule ^(.*)$ $1.fileextension

 

Here's an example of use when wanting to hide the .php file extension:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -£
RewriteRule ^(.*)$ $1.php

 

You will also need to make sure that you have this code in your .htaccess file above the code above:

Options +FollowSymLinks
RewriteEngine On

 

 

 

Some Needed To Know Notes!

 

 

Some of the condition explained:

  • RewriteEngine On - This tells Apache to turn on its Rewrite Rules, similarly if you set RewriteEngine to off it will tell Apache to turn its Rewrite Rules off.

  • RewriteCond - RewriteCond is a cumulative rule. It means that you can’t just have a RewriteCond, you also have to have a RewriteRule.

  • RewriteRule - RewriteRule can compare a URL against just able any criteria and rewrite the url according to your specifications.

 

NOTE:

  • That using this method will mean that all your websites site pages must be in the same file format e.g. PHP, HTML etc.

  • If you have the same directory as file name it will redirect you to that directory so make sure that your directory folder names aren't the same as the file names.

 

 

Share this post


Link to post
Share on other sites

wowsh, thanks for this tut. I learned some cool stuff, thanks doof :derp:

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×

Important Information

By using this site, you agree to our Terms of Use.