Skip to content

Instantly share code, notes, and snippets.

@tecpromotion
Last active February 13, 2025 17:49
Show Gist options
  • Save tecpromotion/867caccbd2ec6c7d2a5d682055b5e43e to your computer and use it in GitHub Desktop.
Save tecpromotion/867caccbd2ec6c7d2a5d682055b5e43e to your computer and use it in GitHub Desktop.
.htaccess-www-to-non-www #htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]
RewriteEngine On
# Redirect non-www to www
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
# Force HTTPS (if not already HTTPS)
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On
# Redirect www to non-www (force non-www)
RewriteCond %{HTTP_HOST} ^www\.(yourdomain\.com) [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
# Force HTTPS (if not already HTTPS)
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment