Mobile app version of vmapp.org
Login or Join
Moriarity557

: URL rewrite problem on IIS7.5 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

@Moriarity557

Posted in: #Iis7 #UrlRewriting #WindowsServer2008

My aim is to create Friendly URLs for a website hosted on IIS 7.5.

The site has 3 pages with the following URLs:

www.example.com/contact.php?langid=1&title=contact http://www.example.com/technology.php?langid=1&title=technology www.example.com/clients.php?langid=1&title=clients

I'd like the URLs in this format :

www.example.com/1/contact/ http://www.example.com/1/technology/ 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=([^=&amp;]+)&amp;title=([^=&amp;]+)$" />
</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}&amp;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=([^=&amp;]+)&amp;title=([^=&amp;]+)$" />
</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}&amp;title={R:2}" />
</rule>
</rules>
<outboundRules>
<clear />
<rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^(.*/)clients.php?langid=([^=&amp;]+)&amp;(?:amp;)?title=([^=&amp;]+)$" />
<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;]+)&amp;(?:amp;)?title=([^=&amp;]+)$" />
<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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Moriarity557

1 Comments

Sorted by latest first Latest Oldest Best

 

@Gloria169

The issue is that the action is hard coded to use the same filename. You could add some additional conditions and duplicate the rules, but a simpler option would be to change the RewriteUserFriendlyURL2 action url to:

{R:2}.php?langid={R:1}&amp;title={R:2}


If the title parameter always equals the filename.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme