SEO URLs for OpenCart Using a “web.config” File on Windows IIS Server

I always suggest Linux hosting for any OpenCart installations. The main OC developers either don’t know much about Windows IIS or neglect to include the necessary SEO URL configuration file for it to work.

This omission results in “not found” 404 (dead link) errors when you visit a page with an SEO URL assigned after enabling SEO URLs in your OpenCart store settings.

Here are the relevant rules from a default OpenCart 2.3.0.2 “htaccess” file…

RewriteEngine On
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

And here is a comparable “web.config” file for Windows IIS servers…

<?xml version="1.0"?>
<configuration>
	<system.web>
		<rewrite>
			<rules>
				<rule name="Google Sitemap" stopProcessing="true">
					<match url="^sitemap.xml$"  />
					<action type="Rewrite" url="index.php?route=extension/feed/google_sitemap"  />
				</rule>
				<rule name="Google Base" stopProcessing="true">
					<match url="^googlebase.xml$"  />
					<action type="Rewrite" url="index.php?route=extension/feed/google_base"  />
				</rule>
				<rule name="Downloads Folder" stopProcessing="true">
					<match url="^system/download/(.*)"  />
					<action type="Rewrite" url="index.php?route=error/not_found"  />
				</rule>
				<rule name="Everything Else" stopProcessing="true">
					<match url=".*"  />
					<action type="Rewrite" url="index.php?_route_={R:1}" appendQueryString="true" />
				</rule>
			</rules>
		</rewrite>
	</system.web>
</configuration>

Hope it helps someone else out there!

Feel free to leave a comment 😉

Leave a Reply

Your email address will not be published. Required fields are marked *