Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»General Articles»How to Set Up 301 Permanent Redirect via .Htaccess

    How to Set Up 301 Permanent Redirect via .Htaccess

    RahulBy 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.

    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
    Previous Article15 Best Security Tips for LAMP Stack
    Next Article Error installing mysql2 Gem on Linux

    Related Posts

    How to Find Django Install Location in Linux

    Updated:April 27, 20221 Min Read

    (Resolved) – ReactJS 404 Error on Page Reload

    2 Mins Read

    Adding a New SSH Key in GitHub

    Updated:April 1, 20223 Mins Read

    13 Best Linux Terminal Emulators and Bash Editors

    8 Mins Read

    How To Install Oracle VirtualBox on Debian 11

    2 Mins Read

    10 Best Linux FTP Clients in 2022

    5 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    • (Resolved) Please install all available updates for your release before upgrading
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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