Magento rewrite problem

Oct 31, 2008 at 4:41 PM
Edited Oct 31, 2008 at 4:43 PM
I'm working on getting Magento to run under IIS7 on Windows Server 2008 and I'm having a problem getting the Ionics ISAPI rewriter to produce the same results as with Apache. For some reason when I get a 404 because of missing content, the Ionics rewriter doesn't redirect to the page intended to handle the 404. This situation does work with Magento running under Apache on Windows and interestingly does work when I'm running IIS with the Ionics rewriter in local host.

Here are the rewrite rules from the IsapiRewrite4.ini file:

RewriteLogLevel 3
RewriteLog c:\temp\iirf

############################################
## always send 404 on missing files in these folders

 RewriteCond %{REQUEST_URI} !^/media/
 RewriteCond %{REQUEST_URI} !^/skin/
 RewriteCond %{REQUEST_URI} !^/js/
 RewriteCond %{REQUEST_URI} !^/var/

############################################
## 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]

Coordinator
Oct 31, 2008 at 6:28 PM
Edited Nov 4, 2008 at 6:44 PM
IIRF does not support the leading ! as a way to negate a pattern.
So many people expect this, maybe I should modify the filter to do it.
In any case you can get negation with a negative-lookahead assertion. Something like this:
RewriteCond %{REQUEST_URI} ^/(?!media|skin|js|var)/
That combines all of the four REQUEST_URI conditions into one. If you like each string on its own line, you can still use
RewriteCond %{REQUEST_URI} ^/(?!media)/
RewriteCond %{REQUEST_URI} ^/(?!skin)/
RewriteCond %{REQUEST_URI} ^/(?!js)/
RewriteCond %{REQUEST_URI} ^/(?!var)/
To tell you the truth, if I were doing this I would put it in the RewriteRule itself. The pattern (first arg) in the RewriteRule is matched against the URI. So any RewriteCond that looks at REQUEST_URI could be folded into the RewriteRule itself.
Also, the -l test (for symbolic link) is not currently supported on IIRF. (Is it important in your case?)
In other words. .. . . your rules would re-factor into this:

RewriteLogLevel 3
RewriteLog c:\temp\iirf

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

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

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

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


Nov 4, 2008 at 6:19 PM

Thanks for replying to the original post.

With regard to the –l test (for symbolic link), I don’t know enough about URL rewriting to know if this condition is required within the Magento URL rewrite processing. I noticed that Helicon Tech has a reference to this condition in the documentation section of their latest .NET URL rewriter which states that –l is unsupported because it is senseless within IIS.

http://www.helicontech.com/ape/doc/mod_rewrite.htm

What is the purpose of –l and why is it not relevant to an IIS7 environment?

Thanks,

Jim Cooper

Coordinator
Nov 4, 2008 at 6:44 PM
The -l test in mod_rewrite is to test if a filesystem entity is a link.
A link is a special type of file that points to another file.
It is like a shortcut in Windows, only different.
It is like a junction in Windows, only different.
It is like a hardlink in Windows, and I'm not sure it is different.  (I am not a filesystem expert)   But in any case, the hardlink is very seldom used in Windows. 

I don't know if I would say it is "senseless" but the use of links is much less common on Windows than on Unix. This is why it is probably unnecessary.
No one has asked me to implement this feature in IIRF, though people did ask for the -d and -f features.