Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How to Set Up 301 Permanent Redirect via .Htaccess

    How to Set Up 301 Permanent Redirect via .Htaccess

    By RahulFebruary 4, 20151 Min Read

    Some times we need to change your website url without impacting any issue with pages SEO. A page redirect with 301 permanent tells the search engines that new url has taken place of old url permanently. So search engines will remove old urls from there indexes.

    Advertisement

    Redirect from One File to Other File

    This is helpful if you want to redirect page from http://yourdomain.com/old.html to http://yourdomain.com/new.html.

    Redirect 301 /old.html /new.html
    

    Redirect Site to WWW URL

    Use this setting if you want to keep your site always running www url. This also helpful for SEO.

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

    Redirect Site to Non WWW URL

    If you want to keep your site to run always without www url. This has there own pros and cons. Like using cookies on site.

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

    Redirect Entire Site to New Domain

    Ever you want to change your website domain, you can easily redirect all pages from old url to new url.

    Redirect 301 / http://newdomain.com/
    

    Or you can use following settings.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
    RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301,NC]
    

    301 htaccess redirect
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Error: EACCES: permission denied, scandir (Resolved)

    How To Install Python 3.11 on Ubuntu 22.04 / 20.04

    Excluding URLs from ProxyPass in Apache

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.