Redirect www to non-www on Apache webservers
Question:
How to redirect www to non-www on Apache webservers? Answer:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>
Description:
To automatically redirect all requests from www to a non-www version in a generic way you can use the mod_rewrite module. Insert the code in your htaccess file and all your www requests will be redirected by Apache to a non-www version.
Reference:
Apache mod_rewrite reference
Share "How to redirect www to non-www on Apache webservers?"
Related snippets:
- Change default terminal in VS Code
- Change colors in VS Code integrated terminal
- Change file encoding in VS Code
- Setup HTTPS for local development on Windows 10
- Add cookie in Chrome
- Setup xdebug 3 debugger for PHP
- Set default encoding to UTF-8 using Apache
- Enable compression in Apache using htaccess
- Cache static content using htaccess
- Redirect all requests to index.php using htaccess
- Set X-Frame-Options on Apache webservers
- Redirect www to non-www on Apache webservers
- Automatically redirect HTTP to HTTPS on Apache webservers
- Set X-Content-Type-Options in Apache
Tags:
redirect www to non-www, www to non-www, redirect, apache, htaccess Technical term:
Redirect www to non-www on Apache webservers