Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Too many redirects with Virtual Host and htaccess [closed]

The issue im getting is too many redirects.

I have a WAMP server that hosts a few sites, but I have a particular site with about 5 domains. I want them all to point to the correct website folder and all to be redirected to a single domain for SEO purposes. Here is what it looks like in the virtual hosts file:

<VirtualHost 50.62.82.101>
ServerAdmin [email protected]
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:

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

Am I only supposed to have one or the other? I have 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

like image 985
Hovaness Bartamian Avatar asked Apr 05 '13 03:04

Hovaness Bartamian


1 Answers

You need to check for the hostname 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]
like image 176
Jon Lin Avatar answered Sep 20 '22 18:09

Jon Lin