Dino Geek, try to help you

How to remove www from URL?


To remove the “www” from a URL, you generally need to perform URL rewriting. This can be achieved through various methods such as server configuration files, application-level settings, or DNS records. Here, I’ll discuss the most common and effective methods: using an `.htaccess` file for Apache servers, using Nginx configuration, and making DNS adjustments.

  1. Apache Server Using `.htaccess`

Apache’s `.htaccess` file is a powerful tool for URL rewriting. Here’s an example of how you can remove the “www” prefix:

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

  1. Explanation:
    - `RewriteEngine On`: Enables the runtime rewriting engine.
    - `RewriteCond %{HTTP_HOST} ^www\.(.)$ [NC]`: Checks if the requested URL starts with “www.”, ignoring case (`NC` flag means “no case”).
    - `RewriteRule ^(.
    )$ http://%1/$1 [R=301,L]`: Redirects to the non-www version of the site. `%1` is the part of the host that matched `(.*)` in the `RewriteCond`. `R=301` signifies a permanent redirect, and `L` specifies that this is the last rule to apply.

  1. Nginx Server

In Nginx, you can include the following in your server block to handle the removal of “www”:

```
server { listen 80; server_name www.example.com; return 301 $scheme://example.com$request_uri;
}
```

  1. Explanation:
    - `listen 80;`: Instructs the server to listen on port 80.
    - `server_name www.example.com;`: Specifies the server block for the www version.
    - `return 301 $scheme://example.com$request_uri;`: Redirects to the non-www version using a permanent redirect (301).

  1. DNS Settings

In some cases, you might also want to make DNS adjustments. While DNS changes alone can’t remove “www” from a URL, they can complement your server configuration. You can set up a CNAME record to point “www” to your root domain:

- Type: CNAME
- Name: www
- Value: @ (or your root domain, e.g., example.com)

This ensures that any request to “www.example.com” will be treated the same as “example.com”.

  1. Application-Level Settings

Many Content Management Systems (CMS), like WordPress, have configurations at the application level to control URL structure. For instance, in WordPress:

1. Go to the Admin Dashboard.
2. Navigate to Settings > General.
3. Update the “WordPress Address (URL)” and “Site Address (URL)” to remove “www”.
4. Save changes.

  1. Examples

To illustrate, let’s say your site is `www.mysite.com`. By configuring Apache:

1. Add the specified `.htaccess` rules in your website directory.
2. Restart Apache to apply changes: `sudo systemctl restart apache2`.

For Nginx:

1. Edit the site configuration file.
2. Add the server block as shown.
3. Restart Nginx to apply changes: `sudo systemctl restart nginx`.

These modifications will guide any requests for `www.mysite.com` to `mysite.com`.

  1. Sources

1. Apache Official Documentation – https://httpd.apache.org/docs/current/
2. Nginx Official Documentation – https://nginx.org/en/docs/
3. WordPress Codex – https://codex.wordpress.org/Changing_The_Site\_URL
4. DigitalOcean Tutorials – https://www.digitalocean.com/community/tutorials
5. DNS Configuration Tutorials – https://dnsimple.com/

These resources provide comprehensive information on configuring and applying URL redirection and management techniques.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use