Support Knowledge Base

URL Rewriting on IIS7 with PHPKB Knowledge Base Software

If you are facing the URL rewriting problem on a windows server, please note that II7 does not support .HTACCESS file syntax for URL rewriting. For earlier versions of IIS (less than 7), you need a tool called ISAPI_ReWrite from HeliconTech which enables the IIS to use .htaccess files exactly like they are used by mod_rewrite of Apache web server.

IIS 7 uses a file called web.config to hold settings for integration with applications. If you want to make your knowledge base URLs SEO friendly, then you have to use web.config file for URL rewriting instead of .HTACCESS. The web.config file contains information that control module loading, security configuration, session state configuration, and application language and compilation settings. Web.config file can also contain application-specific items such as database connection strings.

Now the question is how to make web.config file from .HTACCESS file? IIS 7 includes the URL Rewrite module. You can use this extension to provide rules for IIS to rewrite incoming URL requests. The most common use of URL Rewriting is to provide shorter, easy-to-remember URLs. Many PHP applications including "PHPKB Knowledge Base Software" come with rewrite rules as part of their .htaccess file. These rules tell Apache mod_rewrite() how and when to rewrite incoming requests. The IIS 7 URL Rewrite module can read these rules and translate them into URL Rewrite rules.

For an example sample application, the relevant mod_rewrite rules in the .htaccess file are:

HTACCESS Syntax

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


The IIS URL Rewriter module can read these rules and translate them. The translated URL Rewriter rules are:

Web.config Syntax

<rewrite>
<rules>
<rule name="Imported Rule 1? stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.example.com/{R:1}" />
</rule>
<rule name="Imported Rule 2? stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>

3.33 (6)
Article Rating (6 Votes)
Rate this article
Attached Files
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Name
Email
Security Code Security Code
Related Articles RSS Feed
Enterprise Wiki Software - Criteria for selection and evaluation of wiki software
Viewed 6132 times since Fri, Aug 26, 2016
How do I disable Strict Mode in MySQL?
Viewed 9566 times since Tue, Mar 14, 2017
How to upgrade from PHPKB version 7.x to 8.0
Viewed 6250 times since Mon, Jan 23, 2017
I am getting "The File Type is not allowed" error, what shall I do?
Viewed 5068 times since Wed, Mar 15, 2017
How to use Import From HTML Module?
Viewed 16811 times since Fri, Nov 9, 2012
Article Links - Adding a link to an article in the knowledge base
Viewed 27128 times since Wed, Jan 30, 2013
How to install wkhtmltopdf and configure in PHPKB
Viewed 11908 times since Fri, Dec 11, 2015