0

I have changed my domain name. I want to redirect users when they type old URL...

suppose Old URL was: Google and New old URL is : googled

So when a user enters my old URL, it should redirect to new URL..

can we manage this through magento admin area?

or we have to write it in magento htaccess file?

asked Feb 18, 2015 at 6:38

2 Answers 2

1

If you simply want to redirect your old domain, to the new domain, and the pages are all the same paths, you'd be best to get this done via .htaccess and rewite rules

This will work for that:

# Redirect all pages from olddomain.com
# to newdomain.com
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/1ドル [R=301,L]

Remember that for any type of URL rewrite, using magento's internal rewrite system is a lot more 'expensive' on resources than making use of webserver rewrites.

I generally try and use .htaccess rules if the rewrite is to do a redirect (301's, 302's etc) - way less resource intensive.

If, however, you have to use magento rewrite system, entering a lot of URLs via the admin can be tedious, and time consuming.

What you can do instead, is to do it programatically Either by a basic extension, that purely runs a setup script, or via a shell script.

The install script would be something like this:

<?php
$installer = $this;
$installer->startSetup();
$urlMap = array("old url path" => "NEW PATH",
"old-url-path.html" => "new/url/path.html",
"some/more/url/changes" => "another-new-path.html",
.....
.....
);
try {
 foreach($urlMap as $old => $new) { 
 Mage::getModel('core/url_rewrite')->loadByIdPath($old)
 ->setIdPath($old)
 ->setRequestPath($old)
 ->setTargetPath($new)
 ->setIsSystem(0)
 ->setOptions('RP')
 ->setType(Mage_Core_Model_Url_Rewrite::TYPE_CUSTOM)
 ->save();
 }
} catch (Exception $e) {
 Mage::logException($e);
}
$installer->endSetup();
answered Feb 18, 2015 at 8:33
4
  • Proxiblue that's what i want... Can you please tell me... can i write this from custom module? Commented Feb 18, 2015 at 14:38
  • Yes, you can place the code given into your module install scripts. ref: inchoo.net/magento/… if you are not sure about how that works. Commented Feb 18, 2015 at 14:44
  • Done with domain name... Now I have diffrent urls... because i moved from opencart to magento.. so every product url is diffrent... suppose i have product url in opencart www.example.com/index.php?product=33 and in i've www.example.com/index.php/lock.html and same as many others.... i've created a module that takes all old urls and new urls and saves in database table.. but having issue to write those old and new urls from db table to .htaccess file... Hope you understand my problem... Commented Feb 19, 2015 at 12:37
  • How many urls are we talking about here? 1000's? If not to many, simply use magento's rewrite system, as explained in the second part of the answer. However, as you explained in your comment, you are really looking for ID to PRODUCT mappings. I suggest you read up on RewriteMaps (httpd.apache.org/docs/2.4/rewrite/rewritemap.html) - especially see the section on 'txt: Plain text maps' - their example is the exact thing you want (flipped). Unfortunately this is out of scope for this stack, and you'd be best to ask webmasters.stackexchange.com for more help Commented Feb 19, 2015 at 16:08
1

You can do it in either Magento or with Apache rewrite rules. If the URLs are all the same with just a different domain, then Apache rewrite would be the easiest. If you have to map all the old URLs to a completely different URL structure, then you might want to use Magento. The only issue you are going to have is setting up the second domain on the same store. You may need to create a new store for the purpose of handling the redirects. You should also look into rewritemap. It will have better performance than Magento redirects.

http://httpd.apache.org/docs/2.4/rewrite/rewritemap.html

In either case, be sure to 301 redirects.

answered Feb 18, 2015 at 6:51
5
  • I have many URLs to redirect? what should be the best? and please give an example , how to do that? Commented Feb 18, 2015 at 7:00
  • Here is a video tutorial on Magento rewrites. You will want "custom". youtube.com/watch?v=h0Urg7T5iR8 Commented Feb 18, 2015 at 7:10
  • @Arslantabassum: define : many. Is it just the domain that changed? so actual url path is the same, in all the many urls? Commented Feb 18, 2015 at 8:14
  • @ProxiBlue I have different urls.. Commented Feb 18, 2015 at 14:13
  • @Arslantabassum, a bit confused, as this does not match your question, which states that you just changed your domain. That would then not imply many different URLs that require rewrite since the structure of your site would remain. Commented Feb 18, 2015 at 14:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.