Skip to main content

Apache redirect examples

Member for

3 years 1 month
Submitted by admin on

Redirect rules in apache .htaccess are very useful. Below are some examples that allow you to achieve some simple tasks that I use on a regular basis.

Testing to see if htaccess is working?

The best thing to do in this circumstance is find or create a file called .htaccess in your root directory and add a whole lot of characters and then open your browser. Navigate to the url in the browser. Refresh the page and you will either see an error from the web server or you'll get a blank page.

I want to customise my 404 redirect page

Create a document and call it anything you like and add it into any directory you like from public_html.

ErrorDocument 404  /error/404.php

301 Redirect my website using .htaccess

Have you ever found yourself wanting to do a redirect? Create a .htacess file and then add the following code. Change the url to anything you would like and if the rewrite engine is on it should work.

RewriteEngine On
RewriteRule (.*) http://purencool.com/$1 [R=301,L]

Redirect the index page

Need to redirect the homepage for a couple of minutes? Create a document and call it anything you like .html and add it into any directory you like from public_html and use the code below

DirectoryIndex /pnc/purencool.html