Magento: www or non-www URL redirecting to homepage

You have a Magento website with Base URL = http://example.com/

Working: http://example.com/category-one.html
Not working: http://www.example.com/category-one.html (redirecting to homepage)

 

The only difference in the above two URLs is that the second URL has “www” in it.

Similary, you may have another Magento website with Base URL = http://www.example.com/

In this case,

Working: http://www.example.com/category-one.html
Not working: http://example.com/category-one.html (redirecting to homepage)

So, it depends upon the Base URL (System -> Configuration -> Web). If your base URL has ‘www’ in it then all URLs with ‘www’ will work and URLs without ‘www’ will redirect to homepage.

Solution:

By adding few lines of code in your .htaccess file, you can 301 redirect the undesired/unused URL to desired/used URL. The 301 status code means that a page has permanently moved to a new location.

1) Redirecting ‘non-www’ URLs to ‘www’ URLs

Suppose, you have base URL as http://www.example.com/ then you can do 301 redirect to all ‘non-www’ URLs to ‘www’ URLs.

So, http://example.com/category-one.html will be redirected to http://www.example.com/category-one.html

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

2) Redirecting ‘www’ URLs to ‘non-www’ URLs

You can also redirect ‘www’ URLs to ‘non-www’ URLs.

So, http://www.example.com/category-one.html will be redirected to http://example.com/category-one.html

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

 

http://www.siteground.com/tutorials/magento/magento_issues.htm
http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www
http://davidwalsh.name/no-www
http://blog.chapagain.com.np/magento-www-or-non-www-url-redirecting-to-homepage/
http://magento.stackexchange.com/questions/1332/redirected-to-the-homepage-when-removed-www-from-url

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

OR

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

Most common Magento SEO issues

The following list with common Magento seo issues is for all shop owners to prove there stores. If you launch a new store this checklist will help you to configure most basic SEO settings for Magento.

 

    1. These settings can be managed in your Magento administration panel.

      The Magento Homepage – Title „home“
      It happens very often that a new shop launches with a homepage title „Home“.
      To fix this issue please give your homepage title a better name.

      A good title should contain some of the main keywords, that are relevant for your business.
      Example: Keyword1 Keyword2 – Retail Store – your.storename.com

      This setting can be found at: System–>Configuration–>Design–>HTML Head–>Default Title

    2. The Default Description
      This field should be leaved blank, because it generates duplicate descriptions on every page where no meta description is written. For the products and categories „meta descriptions“ you can use our SERP editor to write clean and beautiful descriptions.

      Take a look at: SERP editor http://www.mgt-commerce.com/magento-serp-editor-extension.html

      The default description setting can be found at: System–>Configuration–>Design–>HTML Head–>Default description

    3. The Default Keywords
      Do not use these standard keywords „magento, magento commerce”. Leave this field blank if you didn’t setup meta keywords for every product, category and CMS page.
      In other case you get default keywords on each page where no meta keyword is set.

      The default keyword setting can be found at: System–>Configuration–>Design–>HTML Head–>Default Keywords

    4. Turn on „index, follow“
      This is a often seen issue and can happen when a shop is fresh released. In general we recommend to use a subdomain with a htaccess pass in development stage.

      You got two big benefits.
      a) You take no risk that a search engine will find your content before it is released.
      b) You can setup all settings like they should be when the shop will migrate to the productive system.

      This setting can be found at: System–>Configuration–>Design–>HTML Head–> Default robots “INDEX, FOLLOW”.

    5. The „Logo Title“ alt „Magento Commerce“
      Often the store owner forgets to setup a correct alt title and name for the „Logo“, so a lot of magento stores have a „Logo title“ = Magento Commerce.

      This setting can be found at: System–>Configuration–>Design–>Header–>Logo Image Alt

      You can leave the field „Welcome Text“ blank

    6. Turn on rel=canonical
      This setting can help you a lot to reduce a duplicate content issue.

      We recommend to turn the canonicals on for both: products and categories.

      This setting can be found at: System–>Configuration–>Catalog–>Search Engine Optimizations„Use Canonical Link Meta Tag For Categories“ and „Use Canonical Link Meta Tag For Products“

    7. Use Categories Path for Product URLs
      We recommend to set this feature on „No“, because if you change your category names, it can happen that a lot of pages, which where indexed by the search engine, are gone.

      Once you have set this on „Yes“, please do not touch it anymore!

      This setting can be found at: System–>Configuration–>Catalog–>Use Categories Path for Product URLs

    8. Create Permanent Redirect for old URLs if Url key changed
      This setting should be set on „Yes“, because if you change something on your Url keys the search engine should know, that the page has moved to a new Url.

      This setting can be found at: System–>Configuration–>Catalog–>Create Permanent Redirect for old URLs if Url key changed

    9. Use Web Server Rewrites and Domain Name www vs. no www

      At first, please decide what you like to use for your domain name.

      There are two options:

      Example with www : http://www.your-domain.com

      Example with no www: http://your-domain.com

      Both options have no effect on your SEO ranking at all, but having a shop which delivers the content for both at the same time means getting a duplicate content issue.

      Please setup your domain at: System–>Configuration–>Web–>Unsecure–>Base URL

      Now you need to make sure that you don´t generate duplicate content by delivering your shop pages with www and none www at the same time.

      For this please enable the option: System–>Configuration–>Web–>Search Engines Optimization–>Use Web Server Rewrites on „Yes“.

      Also you should check your .htaccess file for an automatic redirect.

      For this please open your .htaccess file with an editor and add this line if you’d prefer to use “www” in all of your URLs:

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

      and for no www

      RewriteEngine On
      RewriteBase /
      RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
      RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
    10. Create a sitemap.xml
      Sometimes it happens that a shop owner forgets to create a sitemap.xml or it is created with sample products and categories. A sitemap is important to submit new products to Google & Co.

      A sitemap can be created at: Catalog–>Google Sitemap

      Please double check what´s in your sitemap before you submit it to google webmaster tools!

Get csv data in array php also in Magento

<?php
define(‘MAGENTO’, realpath(dirname(__FILE__).”/..”));
require_once MAGENTO . ‘/store/app/Mage.php’;

umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$write = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$count = 0;
$headers = array();

$file = fopen(MAGENTO . ‘/meta.csv’, ‘r’);

$_category = Mage::getSingleton(‘catalog/category’);

$file = file_get_contents(“meta.csv”);
$datas = array_map(“str_getcsv”, preg_split(‘/\r*\n+|\r+/’, $file));

foreach ($datas as $data)
{ if($data[0])
{
$_category->load($data[0]);
$_category->setMetaTitle($data[2]);
$_category->setMetaDescription($data[3]);
$_category->save();
}
}

https://www.sonassi.com/knowledge-base/magento-kb/magento-batch-update-category-quick-script/

 

How to increase page view to 500 on Sales Order Grid & Other modules.

Edit the grid.phtml file located:

…/app/design/adminhtml/default/default/template/widget/ folder.

approximate at line 81-87:

<select name="<?php echo $this->getVarNameLimit() ?>” onchange="<?php echo $this->getId() ?>JsObject.loadByElement(this)"> 
<option value="200"<?php if($this->getCollection()->getPageSize()==200): ?> selected="selected"<?php endif; ?>>200</option> 
<option value="300"<?php if($this->getCollection()->getPageSize()==300): ?> selected="selected"<?php endif; ?>>300</option> 
<?php if(Mage::app()->getRequest()->getControllerName()=='sales_order') { ?>
 <option value="500"<?php if($this->getCollection()->getPageSize()==500): ?> selected="selected"<?php endif; ?>>500</option>
 <option value="5000"<?php if($this->getCollection()->getPageSize()==5000): ?> selected="selected"<?php endif; ?>>5000</option>
 <?php } ?> 
</select>