Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Broken images using ISAPI Rewrite 3 on IIS



12:40 pm on Aug 12, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 13, 2002
posts: 139
votes: 0

Hi everyone

I'm running on Windows 2003, with IIS and ISAPI_Rewrite 3, so please forgive me :)

Everything with my code below works perfectly, except for images. All of them are broken. I have tried using the full URL, e.g. http://www.example.com/iamges/myimage.gif and I have tried just using a preceding '/' (e.g. /images/myimage.gif

Nothing has worked, the images are still broken.

I am wondering whether it is an IIS issue rather than a Mod Rewrite issue?

RewriteEngine on
RewriteBase /
RewriteMap topic txt:topic.txt
RewriteMap brand txt:brand.txt
RewriteMap series txt:series.txt
RewriteMap model txt:model.txt

RewriteRule ([^/]*)/([^/]*)/([^/]*)/([^/]*)/style/([^/]*)\/ /index2.php?topic=${topic:$1}&brand=${brand:$2}&series=${series:$3}&model=${model:$4}&id=$5
RewriteRule ([^/]*)/([^/]*)/([^/]*)/([^/]*)\/ /index2.php?topic=${topic:$1}&brand=${brand:$2}&series=${series:$3}&model=${model:$4}
RewriteRule ([^/]*)/([^/]*)/([^/]*)\/ /index2.php?topic=${topic:$1}&brand=${brand:$2}&series=${series:$3}
RewriteRule ([^/]*)/([^/]*)\/ /index2.php?topic=${topic:$1}&brand=${brand:$2}
RewriteRule ([^/]*)\/ /index2.php?topic=${topic:$1}

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

Thank you :)

6:23 pm on Aug 12, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

I note that none of the regular-expressions patterns in your rules which rewrite to index2.php have anchors. This can cause trouble. In particular your last rule, which passes only "topic" will accept *any* URL for any resource located in any subdirectory, use the subdirectory as "topic", and discard anything that follows it in the requested URL.

So, if your images are in a subdirectory named "/images", then a request for /images/logo.gif will be rewritten to /index2.php?topic=images and "logo.gif" will be discarded.

So the question is, do you intend for index2.php to serve your images? If not, then I'd suggest excluding any request which includes a filetype in the final path-part from all of your rewrite rules, and using fully-anchored regular-expressions patterns.

Anchoring example:

 RewriteRule ^([^/]+)/$ /index2.php?topic=${topic:$1} 

Also, note that since the question has to do with ISAPI Rewrite, it really belongs in the Microsoft IIS Web Server and ASP.NET forum. If the suggestions above do not help, we can move this thread there.



10:18 pm on Aug 14, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 13, 2002
votes: 0

Thank you Jim. You've pointed me in the right direction, with partial success. Next week I will be back on the case to get it working 100% :)

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members