Home > Software engineering >  htaccess error on redirect - too many redirects
htaccess error on redirect - too many redirects

Time:03-19

I'm trying to redirect all requests from one domain (domain.co.in) to another domain (domain.info.in). I've tried Rewrite directives and Redirect directive in htaccess, but getting too many redirects error in browser. Below is the configuration I'm trying to implement.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.in [NC]
RewriteRule ^(.*)$ index.php/$1 
RewriteRule ^(.*)$ http://domain.info.in/$1 [R,L]

My actual working htaccess configuration is

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(. )$ index.php/$1 

Using this, I'm able to redirect all requests to index.php and working fine. But when I add domain rewrite rules, I'm getting the redirect error. I've tried Redirect directive also, Redirect 302 / http://domain.info.in/index.php/$1, but same error.

I tried the Fiddler tool mentioned in this post, Tips for debugging .htaccess rewrite rules. There it is working good.

Actually, I want to redirect all requests (www.domain.co.in, domain.co.in, www.domain.info.in) to domain.info.in

Any suggestions on this?

CodePudding user response:

As per @CBroe's suggestion, I've updated the configuration and it works. As he said,

RewriteConds always affect the directly following rule.

And I've also added negation to the checking to redirect all other requests.

RewriteEngine On

RewriteCond %{HTTP_HOST} !^domain.co.in$ [NC]
RewriteRule ^(.*)$ http://domain.info.in/$1 [R,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(. )$ index.php/$1 [L]
  • Related