apache tutorial - .htaccess - apache - apache web server - apache server - apache2
.htaccess features 7 : Redirect to Maintenance Page + allowing particular IP
- Redirecting visitors to a maintenance page or other temporary page is an essential tool to have in your tool belt. Using HTAccess, redirecting visitors to a temporary maintenance page is simple and effective.
- All you need to redirect your visitors is the following code placed in your site’s root HTAccess:
.htaccess features 8 : Redirect www to non-wwwSome people prefer to use www.wikitechy.com, but some people prefer the shorter wikitechy.com. There isn’t really a right or wrong way to do it, but whatever you choose you can make sure all of your visitors get sent to the same place. With a few simple rules on the server you can choose from non-www to www, or redirecting from www to non-www.
rewriterule htaccess :Just replace wikitechy.com with your website and you can put this code in .htaccess file in your apache web server,
.htaccess features 9 : Redirect non-www to wwwrewriterule htaccess :
- Just replace wikitechy.com with your website and you can put this code in .htaccess file in your apache web server,
- Both of these rules send a full search engine friendly 301 HTTP redirect. They also preserve the entire URL (so yoursite.com/about redirects to www.yoursite.com/about).
.htaccess features 10 : Visitor IP Banning
.htaccess features 11 : Disable Hot LinkingThe below htaccess code is used to disable hot linking of common file types from other sites, so only your own domain(s) are allowed to reference/ access them. For example, by disabling hotlinking on .gif files, any site not within the allowed list of domains will get a broken image when they try to reference a .gif file that’s on your server
rewriterule htaccess :
Just replace wikitechy.com with your website and you can put this code in .htaccess file in your apache web server,
.htaccess features 12 : Prevent viewing of .htaccess file
- If you use htaccess for password protection, then the location containing all of your password information is plainly available through the htaccess file.
- If you have set incorrect permissions or if your server is not as secure as it could be, a browser has the potential to view an htaccess file through a standard web interface and thus compromise your site/server.
- However, it is possible to prevent an htaccess file from being viewed in this manner:
The first line specifies that the file named .htaccess is having this rule applied to it. You could use this for other purposes as well if you get creative enough.
.htaccess features 13 : htaccess password - Protecting Files or Directories with .htaccess and .htpasswd
- .htaccess and .htpasswd files - These two files work hand-in-hand to require a valid username and password when accessing a file; if no such password is provided, they simply display a “Restricted Access” error message and the invalid user is turned away.
- This is the perfect way to protect
- sensitive files,
- administration areas,
- sensitive login screens, from malicious hackers
- htaccess htpasswd - The first step in this process is to create an .htpasswd file and place it into the directory where the protected file is located.
- If it’s protecting a given directory, the .htpasswd file should be placed inside that protected directory.
- The content of the file is really easy to create, as it contains a username and password separated by a colon. Here’s the basic setup:
- That single line of text goes into the .htpasswd file and that file is immediately uploaded to the server. If there should be more than one user and password combination that can grant access to the file or directory, they can be listed on separate lines with the .htpasswd document.
- To create the authentication screen that requires one of the valid username and password combinations to be entered, site administrators need to add the following series of lines to their.htaccess file, requiring the password document and assigning it to a given directory or file:
- All you needs to do is to point to the relevant .htpasswd file, specify the file or director being protected, and then give the page a title. That title will appear within the login form that is automatically generated by the browser when it encounters this restriction.