1 / 7

. htaccess Apache server directives

. htaccess Apache server directives. BTM 395: Internet Programming. 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

esben
Download Presentation

. htaccess Apache server directives

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. .htaccessApache 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 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-395 • Code 302 by default • Changed URLs • Signals permanent changes in a URL • Use Code 301 • In WordPress, many 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 .htaccess • Even more comprehensive but not so simple Ultimate guide to .htaccess directives

More Related