0

Below is description with Example :

I have 2 sites www.severnsaleslabequip.com and www.qualimet.co.uk with same admin (backend ).

Now www.qualimet.co.uk site is no longer to needed so I want to redirect it to www.severnsaleslabequip.com/index.php/metallurgy-and-microscopy/metallurgy.html using index.php or .htaccess.

Right now I am using index.php file to redirect site but it's not working perfect.

I have placed below code to my index.php file to redirect site

if ($_SERVER['HTTP_HOST'] == "qualimet.co.uk") {  
header('Location: http://www.severnsaleslabequip.com/index.php/metallurgy-and-microscopy/metallurgy.html');
die;
$mageRunCode = "qualimet";
$mageRunType = "website";
}

So when I enter url www.qualimet.co.uk it should be redirect to www.severnsaleslabequip.com/index.php/metallurgy-and-microscopy/metallurgy.html but not in my case.

And if I want to redirect site using .htaccess how can I do?

So please show me both the way (using index.php and .htaccess) to redirect site. Thanks.

UPDATE

I have add below code to my .htaccess (**on magento root path) file.

 RewriteEngine on
RewriteCond %{HTTP_HOST} !http://www.qualimet.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.severnsaleslabequip.com/index.php/metallurgy-and-microscopy/metallurgy.html [L,R=301]

But when I enter www.qualimet.co.uk in url it's go into loop like http://www.severnsaleslabequip.com/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html/index.php/metallurgy-and-microscopy/metallurgy.html

  • For this you can use server redirect functionality – Purushotam Sharma Jun 16 '16 at 6:54
  • You can write 301 Redirect for the url in you .htacess file as follows - Redirect 301 qualimet.co.uk severnsaleslabequip.com/index.php/metallurgy-and-microscopy/… Make sure this is permanent redirect. – Tejas Shah Jun 16 '16 at 6:57
  • @TejasShah check my update in question. – Dhaval Jun 16 '16 at 7:07
  • @User34444 check my update. – Dhaval Jun 16 '16 at 7:07
  • Other option can be from admin > configuration > select scope for > www.qualimet.co.uk website & add the secure & unsecure url as www.severnsaleslabequip.com for this website as well under Web section. So whenever the qualimet.co.uk is hit it will be redirect to new site. – Tejas Shah Jun 16 '16 at 7:16
1

Your redirect rule has two main issues. Firstly the %{HTTP_HOST} variable doesn't include the protocol so it will never match anything and secondly the use of ! at the start tells the rewrite engine to redirect anything that doesn't match the value (which will never match).

RewriteEngine on
RewriteCond %{HTTP_HOST} !www\.severnsaleslabequip\.com$ [NC]
RewriteRule ^(.*)$ http://www.severnsaleslabequip.com/index.php/metallurgy-and-microscopy/metallurgy.html [L,R=301]

The above assumes that www.severnsaleslabequip.com is the only domain in use and says if it's not this domain redirect to the metallurgy page. Another approach would be to perform the redirect only if the request is on the qualimet.co.uk domain.

RewriteEngine on
RewriteCond %{HTTP_HOST} wwww\.qualimet\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.severnsaleslabequip.com/index.php/metallurgy-and-microscopy/metallurgy.html [L,R=301]

As a minor aside, whilst testing rewrites, I'd always use 302, because otherwise you will likely not be seeing the changes you make as your browser and any proxy can cache the 301. Once you're happy the rewrite works, change it to 302.

  • perfect man!!!! – Dhaval Jun 16 '16 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.