Presentation is loading. Please wait.

Presentation is loading. Please wait.

.htaccess Apache server directives BTM 395: Internet Programming.

Similar presentations


Presentation on theme: ".htaccess Apache server directives BTM 395: Internet Programming."— Presentation transcript:

1 .htaccess Apache server directives BTM 395: Internet Programming

2 The.htaccess file Gives Apache various instructions for handling any HTTP request The full, exact name of the file is “.htaccess” –The initial dot indicates a hidden file in Linux –To handle this file in Windows/Mac you MUST set your operating system to display file extensions.htaccess directives (instructions) apply to the folder where you place the file AND to all subfolders –If you add another.htaccess file in a subfolder, a directive there overrides any directives from parent folders This file is very powerful! Be sure to make a backup of your original working.htaccess file before making any changes

3 Common.htaccess directives Rewriting and redirecting URLs Custom error pages Blocking visitors from viewing folder contents Password protection of folders

4 Rewriting vs. redirecting URLs URL rewriting –The visitor enters one URL, Apache internally converts it to an internal address. E.g. Visitor enters: http://wpsite.ca/category/old-post Apache internally rewrites: http://wpsite.ca/?p=123 Visitor never knows what happened –Lots of useful rewrite tricksLots of useful rewrite tricks URL redirection –The visitor enters one URL, Apache serves them back a new URL. E.g. Visitor enters: http://wpsite.ca/category/old-post Apache serves: http://wpsite.ca/category/new-post-name Visitor gets new URL and can update it

5 Redirecting URLs Two main types –Code 301: signals a permanent URL change –Code 302 (the default): signals a temporary URL change Convenience shortcuts –E.g. Redirect /btm395 /bios/pro/teach/btm-395 –Sends requests to http://chitu.okoli.org/btm395 to http://chitu.okoli.org/bios/pro/teach/btm-395http://chitu.okoli.org/btm395 http://chitu.okoli.org/bios/pro/teach/btm-395 –Code 302 by defaultCode 302 by default Changed URLs –Signals permanent changes in a URL –Use Code 301 In WordPress, many plugins exist to handle redirectionmany plugins exist to handle redirection

6 Custom error pages The dreaded “Error 404 Page Not Found” Specify custom error page in.htaccess –ErrorDocument 404 /path/to/errordoc.html Custom error pages in WordPress –Default page is 404.php in the theme –Exact files might be different in your theme –To customize, copy relevant theme files to a child theme and then customize them

7 Other.htaccess directives Blocking visitors from viewing folder contents –Options -Indexes Password protection of folders –Many web hosts have easier tools for password protection Many other.htaccess directives exist –Simple yet Comprehensive guide to.htaccessComprehensive guide to.htaccess –Even more comprehensive but not so simple Ultimate guide to.htaccess directives Ultimate guide to.htaccess directives


Download ppt ".htaccess Apache server directives BTM 395: Internet Programming."

Similar presentations


Ads by Google