Magento help needed

Topics: Developer Forum, User Forum
Aug 6, 2011 at 4:32 AM

I have a client running a Magento 1.4.2 website on IIS 6.  I am having some difficulty in getting the redirects working.  

Their basic url structure is www.domain.com/magento/index.php/category_or_product_name

When I enable web server rewrites, Magento removes the index.php from the links, but I receive a 404 error. trying to get to www.domain.com/magento/category (or a product page, cms page, etc).  Use web server rewrites is turned on in the configuration page for the cart.

The base url is set to www.domain.com/magento

If the iirf.ini is placed in the magento directory for www.domain.com.  This causes a 404 error whenever clicking a link (which has the url www.domain.com/magento/category).  I can still type in the form with index.php/category and get to the page directly.  It seems as if no redirect is taking place at all.  

If the iirf.ini is placed in the root directory, I get a 404 for http://www.domain.comindex.php, which seems to indicate that the rewrite rule is runing but is not correct.  If rewritebase /magento/ is used, then the 404 error is for http://www.domain.com/magento/category.  Ideally, I want the urls to be http://www.domain.com/category

Any insight would be greatly appreciated.

 

I am trying this pattern:

IterationLimit 10  

MaxMatchCount 10  

RewriteEngine ON  

StatusInquiry ON    

#RewriteBase /magento/   

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

############################################  ## rewrite everything else to index.php

RewriteRule ^/(?!media|skin|js|var).* index.php [L]

Coordinator
Aug 7, 2011 at 11:14 PM

Sorry, I don't know magento, so your situation is not clear to me at all.

Aside from the magento details - Your iirf.ini is a confusing;  it may have come into your message incomplete form, and with some corruption. 

  1. There are multiple RewriteCond statements on a single line, which is not valid.  Maybe just an issue of formatting in the discussion forum.
  2. it apparently rewrites everything to index.php, and obliterates any information that was in the original URL. If someone requests /tigerfish , it will rewrite to index.php. If someone else requests /ShoppingCart , it will rewrite to index.php. This may be correct behavior, you should be sure you understand it.  It's confusing to me, and it might be worth commenting in the ini file why you are doing it this way.
  3. finally, those RewriteCond statements "go with" the rewriterule directive that follows, so really you should have them on immediately preceding lines; for best clarity don't put an intervening comment line, especially not one like ########################### between the RewriteCond and the RewriteRule.  The intervening comment seems to indicate they are separate, when they really are not. It should look more like this:
#####################################  
## For any incoming URL that does not begin with one of {media skin js var}, 
## rewrite it to index.php.  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d   
RewriteRule ^/(?!media|skin|js|var).* index.php [L]

Some other observations... you wrote:

> When I enable web server rewrites, Magento removes the index.php from the links,

I don't know what this means. Where is it that you are enabling web server rewrites?   Does magento do URL rewriting?  Your statement implies that it does. If so, why are you using IIRF?  How do the two URL rewriters interact?

you wrote:

> I receive a 404 error. trying to get to www.domain.com/magento/category (or a product page, cms page, etc).

I don't know what this means.  I don't know what "trying to get... <url here>" means.  Does "trying to get" mean, that is the URL you have requested using the browser?  Does it mean, that URL is the result of the rewrite you desire?  You'll have to be more precise in your language.  I'm not trying to be difficult here.  It's just that your explanation is not clear to me.

I know IIRF pretty well.  I don't know magento.  I don't know what it is or what it does.  If you could describe your problem in a way that assumes no knowledge of magento on my part, I may be able to help.

Regarding your use of RewriteBase - you almost NEVER need to specify an argument to that directive.  It accepts an argument just for compatibility with Apache, but you shouldn't specify one if you aren't sure. IIRF can figure out what the base is, from the vdir.  I think one reason you are getting unexpected results may be because you are specifying a value for the base that includes a trailing slash.  I think that's probably wrong. Either use RewriteBase, or don't, but be careful about specifying an argument to it.

You wrote:

>If the iirf.ini is placed in the root directory, I get a 404 for http://www.domain.comindex.php, which seems to indicate that the rewrite rule is runing but is not correct.

Is there a typo in there somewhere?   The URL http ://www.domain.comindex.php - should it have another slash in there?   Also  - are you making an assumption here? Getting a 404 for a URL doesn't necessarily indicate that IIRF is running. 

As for where to put the iirf.ini: it seems like you are not clear on that.  But the answer is very clear: You should put the IIRF.ini in the vdir of the app.  Most apps have a single level of vdirs, so you probably want to put iirf.ini in the top-level filesystem directory that contains your webapp page scripts like index.php.   I am guessing, because I don't know magento or how you have it set up, but there should be no guessing on your part about this.  Where in the filesystem does the vdir refer to?  You should not be unsure about where to put the iirf.ini.  This is a basic thing, and you need to be sure of that before working on anything else.

 

Aug 8, 2011 at 12:25 AM
Cheeso wrote:

Sorry, I don't know magento, so your situation is not clear to me at all.

Aside from the magento details - Your iirf.ini is a confusing;  it may have come into your message incomplete form, and with some corruption. 

  1. There are multiple RewriteCond statements on a single line, which is not valid.  Maybe just an issue of formatting in the discussion forum.
  2. it apparently rewrites everything to index.php, and obliterates any information that was in the original URL. If someone requests /tigerfish , it will rewrite to index.php. If someone else requests /ShoppingCart , it will rewrite to index.php. This may be correct behavior, you should be sure you understand it.  It's confusing to me, and it might be worth commenting in the ini file why you are doing it this way.
  3. finally, those RewriteCond statements "go with" the rewriterule directive that follows, so really you should have them on immediately preceding lines; for best clarity don't put an intervening comment line, especially not one like ########################### between the RewriteCond and the RewriteRule.  The intervening comment seems to indicate they are separate, when they really are not. It should look more like this:
#####################################  
## For any incoming URL that does not begin with one of {media skin js var}, 
## rewrite it to index.php.  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d   
RewriteRule ^/(?!media|skin|js|var).* index.php [L]

Some other observations... you wrote:

> When I enable web server rewrites, Magento removes the index.php from the links,

I don't know what this means. Where is it that you are enabling web server rewrites?   Does magento do URL rewriting?  Your statement implies that it does. If so, why are you using IIRF?  How do the two URL rewriters interact?

Magento has, in its configuration, an option to use web server rewrites (which means that the URLS generated do not have the index.php in them. The cart expects the rewrites to be activated on the web server and written to use a certain format

 

you wrote:

> I receive a 404 error. trying to get to www.domain.com/magento/category (or a product page, cms page, etc).

I don't know what this means.  I don't know what "trying to get... <url here>" means.  Does "trying to get" mean, that is the URL you have requested using the browser?  Does it mean, that URL is the result of the rewrite you desire?  You'll have to be more precise in your language.  I'm not trying to be difficult here.  It's just that your explanation is not clear to me.

It means that when I enter the url in the above format, I am getting a 404 with that url returned, when I expect the url to be rewritten internally as www.domain.com/magento/index.php/category

 

I know IIRF pretty well.  I don't know magento.  I don't know what it is or what it does.  If you could describe your problem in a way that assumes no knowledge of magento on my part, I may be able to help.

Regarding your use of RewriteBase - you almost NEVER need to specify an argument to that directive.  It accepts an argument just for compatibility with Apache, but you shouldn't specify one if you aren't sure. IIRF can figure out what the base is, from the vdir.  I think one reason you are getting unexpected results may be because you are specifying a value for the base that includes a trailing slash.  I think that's probably wrong. Either use RewriteBase, or don't, but be careful about specifying an argument to it.

You wrote:

>If the iirf.ini is placed in the root directory, I get a 404 for http://www.domain.comindex.php, which seems to indicate that the rewrite rule is runing but is not correct.

Is there a typo in there somewhere?   The URL http ://www.domain.comindex.php - should it have another slash in there?   Also  - are you making an assumption here? Getting a 404 for a URL doesn't necessarily indicate that IIRF is running. 

This was my point, that the url is being returned as indicated, without the slash.  I do not have access to the server to directly check that IIRF is running.  However, I can check that it's running by renaming the iirf.ini file and noting the difference in the url (which is why I posted the url as it is being returned).  If there is no iirf.ini then the return is http://www.domain.com/magento

 

As for where to put the iirf.ini: it seems like you are not clear on that.  But the answer is very clear: You should put the IIRF.ini in the vdir of the app.  Most apps have a single level of vdirs, so you probably want to put iirf.ini in the top-level filesystem directory that contains your webapp page scripts like index.php.   I am guessing, because I don't know magento or how you have it set up, but there should be no guessing on your part about this.  Where in the filesystem does the vdir refer to?  You should not be unsure about where to put the iirf.ini.  This is a basic thing, and you need to be sure of that before working on anything else.

Unfortunately, I can't be sure about it.  I don't have access to the server other than ftp access.  I presume from the fact that the url resolves to the base directory that i have access to, that the vdir refers to that folder (and because the web host has told me that was the case).  Their magento installation is in a magento folder within the root for their site (or what I am presuming is the root).  

 

 

 

Aug 8, 2011 at 1:05 AM

I thought I'd simplify things since essentially, what I'm trying to accomplish is this:

 

without web server rewrites turned on in the magento configuration panel, the format of a URL is:

www.domain.com/magento/index.php/productname

Turning on "use web server rewrites" in magento, all magento urls are rewritten to

www.domain.com/magento/productname

In order for this to work, .htaccess needs to be used (or iirf).  Magento ships with the following .htaccess file (not all of it pertains to rewrites, but I'm only posting that section since this editor does not format the file correctly when pasting)

############################################## 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}]
############################################## always send 404 on missing files in these folders
    RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
############################################## never rewrite for existing files, directories and links
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME} !-l
############################################## rewrite everything else to index.php
    RewriteRule .* index.php [L]

 

There may be a further issue, because when I try to use the above format, I'm simply redirecting back to the home page, though the url is being rewritten.

http://www.caraccessories.com/magento/auto-interiors/cargo-liners for example, is simply opening the home page.  I can manually navigate to http://www.caraccessories.com/magento/index.php/auto-interiors/cargo-liners so I am thinking that there needs to be a 301 perhaps to re-insert the index.php as far as the server is concerned?

 

(If you test www.caraccessories.com, I am aware that there is a 301 to the home page which throws a 404 error.  I've already written the web host to remove the /default, which should not have been in the 301 (magento has the ability to host multiple sites, but this has been turned off.. the host still has to change the original 301 redirects they have in IIS which redirect from the old ASP site to the new site).

Aug 8, 2011 at 1:20 AM

I should add that the htaccess file that ships with Magento resides in the magento folder, not the htdocs folder (which is the web root for Apache).

Coordinator
Aug 8, 2011 at 5:23 AM

ok - ....

First: if the magento folder is configured as a vdir or IIS application, then ithat is where you should put the IIRF.ini.  If the magento folder is just a subfolder in the actual physical vdir folder, then the iirf.ini file should reside in the parent folder of the magento folder.  Clear?   IIRF works a little differently from Apache- there is one IIRF.ini file processed per vdir.  (Apache allows .htaccess to be in any subdirectory, I believe.  That's not supported in IIRF).  Put the IIRF.ini file in the physical directory corresponding to the IIS virtual directory (vdir).

ok, now - your rule rewrites to index.php if the REQUEST_FILENAME is neither an actual filesystem file nor an actual filesystem directory.  That is what the -f and -d strings do in the RewriteCond. It appears that this is not working as you expect.  This is something you can diagnose by looking in the IIRF log file.  It will show you the value for REQUEST_FILENAME and the result of the existence test (file or directory).  Set the log level to 4.  (RewriteLogLevel 4)  Be sure to specify an IIRF log file (eg RewriteLog c:\temp\iirflog)

I noticed that you also use the -l test.  This is supported in mod_rewrite but is not supported in IIRF currently.  (I just added it to v2.1.1.28, but that version is not out yet).   So you may want to eliminate that RewriteCond line , for the moment. Until you can upgrade to v2.1.1.28. 

Now, I don't know how magento works - but since every URL is being rewritten to index.php, then I suppose index.php has some smarts in it to detect the original URL, prior to rewrite. This is pretty common, and it is the only way I know of, that index.php could get /auto-interiors/cargo-liners from the original URL, after the rewrite occurs.  If that is the case, then you need to set the original URL in a server variable so that Magento can retrieve it.  I just had a quick look , and it does appear that Magento works in this way - it looks for the server variable  HTTP_X_REWRITE_URL . IIRF sets that variable when the [U] modifier is employed on a rule. 

So to get IIRF to work with Magento, you need to do something like this:

   RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
############################################## never rewrite for existing files, directories 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
############################################## rewrite everything else to index.php
    RewriteRule .* index.php [L,U]

 I recommend trying this first, before examining  the IIRF log for other problems.  This may be just the think you need.

 

Aug 8, 2011 at 7:25 AM

I have it licked.  I may have it licked.  I think.  It appears as if the problem from my original attempts was in leaving out the un-mangling rule [U].  Which makes sense after reading up on the purpose of the rule.  

Now if I can just teach the clients, for the 50th time, how to build their category structure correctly (this is what actually builds the url in Magento) and apparently Google is going back to the days of pre-cms, structured URLs (of which I heartily approve) with their Panda 2.0 initiative.  Anyway, the rewrites appear to be working correctly.  I'll be testing it tonight.. er, this morning.  Thanks for the help.

#RewriteLog c:\inetpub\iirfLogs\iirf   

#RewriteLogLevel 3       

Options +FollowSymLinks   

RewriteEngine on

RewriteBase /magento/

RewriteCond %{REQUEST_URI} !^/(media|skin|js)/

############################################## never rewrite for existing files, directories    

RewriteCond %{REQUEST_FILENAME} !-f   

RewriteCond %{REQUEST_FILENAME} !-d

############################################## rewrite everything else to index.php   

RewriteRule .* index.php [L,U]