Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Web Servers»Apache»How to Add or Remove WWW Prefix in Domain URL

    How to Add or Remove WWW Prefix in Domain URL

    By RahulNovember 9, 20172 Mins Read

    The SEO specialist suggests running website either with www or without www domain only. You can automatically add or remote www prefix from domain’s URL on Apache and Nginx web server. Apache users can do this using .htaccess file with mod_rewrite module enabled. Nginx users can do this in Nginx server block settings. In this tutorial, you will get to add or remove www on Apache (using mod_rewrite) and Nginx web servers.

    Remove WWW Prefix in Domain URL

    Add the following code in your web server configuration. This will remove www from domain site URL. If someone opened the site with www, this will redirect to non-www URL.

    Apache users add the following code in your website .htaccess file. This required the mod_rewrite enabled on your server, without mod_rewrite it will not work anymore.

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

    Nginx users add the following code in domains server block.

    server {
     server_name www.example.com;
       return 301 http://example.com$request_uri;
    }
    

    Adding WWW Prefix in Domain URL

    Add the following code in your web server configuration. This will add www in domain site URL. If someone opened site without www, this will redirect to a domain with www URL.

    Apache users add the following code in your website .htaccess file. Remember to enable mod_rewrite module.

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

    Nginx users add the following code in domains server block.

    server {
     server_name example.com;
       return 301 http://www.example.com$request_uri;
    }
    

    References:
    https://www.nginx.com/blog/creating-nginx-rewrite-rules/
    http://httpd.apache.org/docs/current/mod/mod_rewrite.html

    rewrite siteurl www
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    SQL Queries to Change Domain Name for WordPress Site

    10 Quick Apache Optimization Hacks

    An Introduction to Apache MPM (Multi-Processing Modules)

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Create and Use Custom Python Module
    • How to Install and Use Podman on Ubuntu 22.04 & 20.04
    • Setting Up Laravel with Docker and Docker-compose
    • Setting Up Development Environments with PHP and Docker
    • Using Composer with Different PHP Versions in Linux
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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