Too many redirects with Virtual Host and htaccess

The problem with getting too many redirects.

I have a WAMP server that hosts several sites, but I have a specific site with approximately 5 domains. I want all of them to point to the correct website folder, and all of them should be redirected to the same domain for SEO purposes. Here's what it looks like in a virtual hosts file:

<VirtualHost 50.62.82.101>
ServerAdmin info@hovaness.com
DocumentRoot "c:/wamp/www/example"
ServerName example.com
ServerAlias example.net www.example.com www.examples.net www.examples.com examples.com examples.net
ErrorLog "logs/example.com.log"

The htaccess file looks like this:

RewriteEngine On
RewriteRule ^(.*)$ http://sellingwarriors.com/$1 [R=301,L]
RewriteBase /

Should I only have one or the other? I also tried in the htaccess file:

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

Any help is appreciated.

+5
source share
1 answer

You need to check the host name that you are redirecting to, otherwise it will continue to redirect:

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

All Articles