Code Monkey home page Code Monkey logo

apache-htaccess-docu's Introduction

apache-htaccess-docu

Apache Web server directory level configuration chontrol by htaccess

You can check if .htaccess file is present or not by this php file.

Purpose of htaccess

  • Page redirection
  • Access control
  • Content protection
  • Hot link prevention
  • Cache control
  • Server side error handling
  • Rewrite url
  • Set server time zone

Create .htaccess file in your folder. It would be better to create the file using a text editor in windows. Remember: This commands are case sensitive and should not be tempered unnecessarily.

Redirect domain

RewriteEngine On
Redirect 301 /http:domain-name.extension

This will redirect you to your desired domain in case you changed your previous domain or you want to go user in different path.

User authentication

RewriteEngine On
AuthType Basic
AuthName "Restricted Content"
AuthUserFile absolute-path\.htpasswd
Require valid-user

None without a proper credentials can acces into this path. The creadentials will be written in .htpasswd file. You haveto provide proper or absolute path of .htpasswd file in order to get access credentials. On .htpasswd file user and password are written as a format-

user-name:password

Cache handle

<FilesMatch "\.(file-ext|file-ext|file-ext|file-ext)$">
	Header set Cache-Control "max-age=604800, public"
</FilesMatch>

On the first line shows, file name extensions should be written in order to choose the type of files will be stored in cache. Max-age derives the time cache will be stored. The time is calculated in second here. After this time stored cache file will be destroyed automatically.

Remove file extension from url

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC, L]

Keyword to access root file

RewriteRule ^keyword index.php

In liew of index.php you can write keyword in url to access index.php file. You can add multiple keyword to this path.

Folder access control

options +Indexes   =>grant access
options -Indexes   =>access forbidden

In order to change access permission of app or any valuable folder to users jusht switch - or + symbol.

Redirect http to https

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Using this two lines will redirect your http url to https url. Post your http hort url and request url in place

Deny access using IP

Order allow, deny
deny from the-ip-to-block
deny from the-ip-to-block
allow from all

Using this lines only given IP will be blocked to get access.

Deny access using domains

RewriteEngine on
RewriteCond %{HTTP_REFERER} domain1.com [NC, OR]
RewriteCond %{HTTP_REFERER} domain2.com [NC, OR]
RewriteRule .* - [F]

Then mentioned domain won't get straight access in this case.

Enabling SSI

AddHandler server-parsed .html

SSI also called "Server Side Includes" are directives that are placed in HTML pages, and evaluated on the server while the pages are being served. It could be very useful to create some content's dunamically.

Time zone setup

SetEnv TZ America/Chicago

TZ could be added as a global envirenment variable to that are provided by the servers to eache of the hosted websites for modification.

Custom Error page

ErrorDocument 404 /404.ph or 404.html

In case of any error occurs, this will redirect users to the custom 404 page.

Automatic goto index file if entered directory does'nt exist

<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /mvc/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>

Here RewriteBase works quiet similar to of html.

License and copyright

Licenced under MIT license.

apache-htaccess-docu's People

Contributors

biplob14 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.