1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Magento, store code in URLs and mod rewrite voodoo

Discussion in 'Apache' started by haraldinho, Oct 25, 2010.

  1. #1
    Hey there,

    I am very stuck at the following problem. My e-commerce site is in Magento. It used to have only one store view i.e. language. Now I want to add a second language. In Magento, you can add a store code to the URL, to make a distinction between the languages.

    So where the URL for a specific product used to be like this:

    www.myshop.com/myproduct.html

    it will now become

    www.myshop.com/en/myproduct.html

    with 'en' being the english store view.

    For Google this means trouble, because as soon as I put these modifications live, Google won't be able to find all currently indexed pages anymore. So what I am looking for is mod rewrite voodoo that does the following:
    1. reroute all traffic that comes in with no store code (like 'en') to the 'en' store code
    2. do not reroute anything that already has a store code
    3. do the rerouting as 'permanent' so Google will know it has to change the old URL's to the new ones

    In this article http://www.magentocommerce.com/boards/viewthread/22677/ this is explained. Somebody suggests the following voodoo:

    *** start voodoo snippet *****

    ## redirect do Deutsch if there's no preference in the URL
    RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_URI} !(index.php|de/|fr/|uhu_fr/|k55_de/|k55_en/) #add your own store-views here
    RewriteRule ^(.*)$ de/$1 [R,L] #add your preferred default-store view here

    *** end voodoo snippet *****

    Looks as good voodoo to me, but unfortunately, it leads to a server error (500). It is beyond me why, but I am hoping that somebody out here can point me in the right direction!

    Thanks very much in advance!!

    Haraldinho
     
    haraldinho, Oct 25, 2010 IP
  2. scriptinstaller

    scriptinstaller Peon

    Messages:
    109
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    www.myshop.com/myproduct.html

    how many default pages? are they all in current folder and end in html?


    I see it as simple as this
    RewriteRule ^(.*?).html$ /en/$1.html [L, R=301]
     
    scriptinstaller, Oct 26, 2010 IP
  3. haraldinho

    haraldinho Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi scriptinstaller,

    It isn't as easy as that I'm afraid. Magento uses all kind of mechanisms. Not only .html files but also directories. Not everything is in the current folder.

    Haraldinho
     
    haraldinho, Oct 29, 2010 IP
  4. haraldinho

    haraldinho Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I finally figured out why I got the server error. I had not set the RewriteBase. That wasn't necessary before, but it is now, with these new commands.

    The code snippet below shows the rewrite part of my .htaccess file:

    
    <IfModule mod_rewrite.c>
    
    ############################################
    ## enable rewrites
    
        Options +FollowSymLinks
        RewriteEngine on
    
    ############################################
    ## you can put here your magento root folder
    ## path relative to web root
    
        RewriteBase /magento/
    
    ############################################
    ## workaround for HTTP authorization
    ## in CGI environment
    
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
    
    ############################################
    ## the following is used for rewriting old
    ## URL's without a store code in it to the
    ## new URL format with store codes
    
        # If the request does not match an existing file
        RewriteCond %{REQUEST_FILENAME} !-f
        # and the request does not match an existing directory
        RewriteCond %{REQUEST_FILENAME} !-d
        # and the request does not match a symbolic link
        RewriteCond %{REQUEST_FILENAME} !-l
        # and the request URL does not already contain an existing store code
        RewriteCond %{REQUEST_URI} !(index.php|nl/|en/)
    
        #rewrite to the default store view
        RewriteRule ^(.*)$ nl/$1 [R=301,L]
    	
    	
    
    ############################################
    ## always send 404 on missing files in these folders
    
        RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
    
    ############################################
    ## never rewrite for existing files, directories and links
    
    	# If the request does not match an existing file
        RewriteCond %{REQUEST_FILENAME} !-f
    	
    	# and the request does not match an existing directory
        RewriteCond %{REQUEST_FILENAME} !-d
    	
    	# and the request does not match a symbolic link
        RewriteCond %{REQUEST_FILENAME} !-l
    
    ############################################
    ## rewrite everything else to index.php
    	
        RewriteRule .* index.php [L]
    
    </IfModule>
    
    Code (markup):
    Thanks for the help!

    Haraldinho
     
    haraldinho, Oct 30, 2010 IP