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 😉

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

    1. admin Post author

      I rarely use IIS, so if that no longer works 1) make sure your host checks for the web.config file and 2) you may need to update it to reflect your IIS version (if the spec has changed since I wrote this post).

      Reply
    1. Robert Post author

      Try these rules…

      <rule name="ForceWWW" stopProcessing="true">
      <match url=".*" ignoreCase="true" />
      <conditions>
      <add input="{HTTP_HOST}" pattern="^yoursite.com" />
      </conditions>
      <action type="Redirect" url="https://www.yoursite.com/{R:0}" redirectType="Permanent" />
      </rule>
      <rule name="HTTPtoHTTPS" stopProcessing="true">
      <match url="(.*)" ignoreCase="false" />
      <conditions>
      <add input="{HTTPS}" pattern="off" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
      </rule>

      Be sure to update "yoursite.com" with your actual domain name.

      Reply

Leave a Reply to Dhruveel Dave Cancel reply

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