Redirect www host to non-www Linux Apache modrewrite -

Redirect www host to non-www Linux Apache modrewrite

The below forces all request to your domain to go to the main non-www root domain.

Updated code:

RewriteCond %{HTTP_HOST} !=domain.com
RewriteRule ^(.*)$ https://newurl.com/subdir/$1 [R=301,L]

If you don't want it to go to a subdirectory:

RewriteCond %{HTTP_HOST} !=domain.com
RewriteRule ^(.*)$ https://newurl.com/$1 [R=301,L]

Bad code:

This code is bad because the REQUEST_URI is not valid or correct if you want to rewrite to a subdirectory and may cause a // home page etc...

RewriteCond %{HTTP_HOST} !=domain.com
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^ http://domain.com/%{REQUEST_URI} [R=301,L]


  • Install Windows From a Linux TFTP Server instead of using WDS Solution
  • How To Secure Samba NMBD/SMBD to bind to a specific IP address
  • tftp: client does not accept options - solution if you are using UEFI PXEBoot disable it!
  • Linux how to view video card make and exact model
  • Authentication refused: bad ownership or modes for directory /home/user SSH Public Key Authentication Failed Solution
  • How to Update Linux /usr/share/misc/pci.ids
  • pcimodules and lspci not working alternative solution
  • How to disable Google Fonts in Wordpress
  • Unable to load dynamic library /usr/lib64/php/modules/php_openssl
  • mysqld in Linux hacked
  • W: GPG error: http://archive.debian.org squeeze Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA NO_PUBKEY 64481591B98321F9
  • cannot mount kvm ntfs image
  • h264 DVR security camera footage cannot be played
  • dhcpd.conf how to secure so only known and allowed clients will be given dhcpd IP address leases
  • Thunderbird E-mail List Blank White but e-mails still clickable and viewable
  • css responsive images
  • responsive table without changing much code solution
  • yum how to install old obsolete packages
  • PHP Howto Store Value of Included File Output Into Variable
  • PHP Migration from 5.3 to 5.4+ and dealing with deprecated functions