Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Redirection through htaccess file

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 277
    Comment on it

    .htaccess is the most useful file when we are working with php and apache. The directory level configuration of Apache server software is provided via .htaccess (Hypertext access) files. htaccess files defines mostly all the things like server settings , redirections and all.

    we can do several redirection by using few code below . Redirection can be -

    1-301 Redirect If you want to redirect any old page to new page, just copy the code below and paste it in .htaccess file which should present in your root folder.

    Redirect 301 /old/file.html http://yourdomain.com/new/file.html
    

    If you want to redirect the whole url into now

    Redirect 301 / http://newdomain.com
    

    2-non www to www redirection

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
    RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
    

    3- www to non www redirection

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
    RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
    

    4-http to https redirection

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

    5-https to http redirection

    RewriteCond %{HTTPS} on
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
    

    6-Custom Error Pages

    ErrorDocument 404 /404.php
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: