My aim is to create Friendly URLs for a website hosted on IIS 7.5.
The site has 3 pages with the following URLs:
http://www.example.com/contact.php?langid=1&title=contact
http://www.example.com/technology.php?langid=1&title=technology
http://www.example.com/clients.php?langid=1&title=clients
I'd like the URLs in this format :
http://www.example.com/1/contact/
http://www.example.com/1/technology/
http://www.example.com/1/clients
When I create the friendly URLs in the IIS wizard it uses the same URL pattern
^([^/]+)/([^/]+)/?$
for each of the rules. This just means all 3 URLs redirect to the same page.
the web.config
file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^clients\.php$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^langid=([^=&]+)&title=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="clients.php?langid={R:1}&title={R:2}" />
</rule>
<rule name="RedirectUserFriendlyURL2" stopProcessing="true">
<match url="^contact\.php$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^langid=([^=&]+)&title=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL2" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="contact.php?langid={R:1}&title={R:2}" />
</rule>
</rules>
<outboundRules>
<clear />
<rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^(.*/)clients\.php\?langid=([^=&]+)&(?:amp;)?title=([^=&]+)$" />
<action type="Rewrite" value="{R:1}{R:2}/{R:3}/" />
</rule>
<rule name="OutboundRewriteUserFriendlyURL2" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^(.*/)contact\.php\?langid=([^=&]+)&(?:amp;)?title=([^=&]+)$" />
<action type="Rewrite" value="{R:1}{R:2}/{R:3}/" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<urlCompression doDynamicCompression="false" />
</system.webServer>
</configuration>
Any suggestions how to do this correctly?
RewriteUserFriendlyURL2
action url to something like:{R:2}.php?langid={R:1}&title={R:2}
if title always equals the filename.