Url rewrite to lower case - url-rewriting

I already have the following code in my web.config which does pretty much what I want.
<rewrite>
<rules>
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www.mysite.com$" negate="true" />
</conditions>
<action type="Redirect" url="{MapSSL:{HTTPS}}www.mysite.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapSSL" defaultValue="OFF">
<add key="ON" value="https://" />
<add key="OFF" value="http://" />
</rewriteMap>
</rewriteMaps>
</rewrite>
There is just one element missing from what I can see. The query element of the url will remain as is - mixed/upper case - how can I ensure all of the url is lowercase?

You can add a lowercase rule.
<rule name="LowerCaseRule" patternSyntax="ExactMatch" stopProcessing="true">
<matchurl="[A-Z]" ignoreCase="false"/>
<actiontype="Redirect" url="{ToLower:{URL}}"/>
</rule>
its part of default template, Under Search Engine Optimization (SEO) template, select Enforce lowercase URLs

Related

URL Rewrite Rule to remove www. for all URLs except for 1

I have a working rule that removes www. for all urls coming in. I have a webserivce that the redirect will change from a POST to a GET. I need to exclude the URL https://www.foo.net/WebServices/service.asmx from this rule.
I have looked at other solutions on SO with no success.
<rewrite>
<rules>
<rule name="Remove WWW" enabled="true" stopProcessing="true">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(foo\.net)" />
</conditions>
<action type="Redirect" url="https://{C:2}/{R:1}" />
</rule>
</rules>
</rewrite>
You can do that easily by adding a condition to "not match" (aka adding "negate='true'" ), something like this should work:
<rules>
<rule name="Remove WWW" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.foo\.net$" />
<add input="{URL}" pattern="^/WebServices/service\.asmx$" negate="true" />
</conditions>
<action type="Redirect" url="https://foo.net/{R:1}" />
</rule>
</rules>

Subdomain url-rewrite in web.config

This is how i currently want to redirect my site to
when i try navigating to
http://sub1.sitename.com it should redirect to sitename.com/newprojects/sub1
and the same for sub2
i tried using it like this but it ends up loading www.sitename.com
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="^sub1\.sitename\.com$" ignoreCase="true" />
<action type="Redirect" url="sitename\.com/newprojects/sub1/" redirectType="Permanent" />
</rule>
<rule name="Redirect1" stopProcessing="true">
<match url="^sub2\.sitename\.com$" ignoreCase="true" />
<action type="Redirect" url="sitename\.com/newprojects/sub2/" redirectType="Permanent" /> </rule>
</rules>
</rewrite>
You could try matching all the URL's and then filtering based on what you want to redirect.
<rewrite>
<rules>
<rule name="sub1 redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^sub1\.site\.com(/)?$"/>
<add input="{PATH_INFO}" pattern="^/newprojects/sub1/" negate="true" />
</conditions>
<action type="Rewrite" url="\newprojects\sub1\{R:0}" />
</rule>
</rules>
</rewrite>
this worked for me.

Why won't this URL Rewrite rule fire?

Rule is
<rule name="Redirect to new host" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern=".*mycompany\.com/blogs(.*)" />
</conditions>
<action type="Redirect" url="http://blogs.mycompany.com{C:1}" />
</rule>
The module's built-in pattern tester says that http://subdomain.mycompany.com/blogs/blog1 matches, so it should redirect to http://blogs.mycompany.com/blog1, but nothing happens. Would greatly appreciate help fixing this rule or writing one that does work!
It's work:
<rule name="Test" stopProcessing="true">
<match url=".*" />
<conditions trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="^.*mycompany\.com$" />
<add input="{URL}" pattern="^/blogs(.*)$" />
</conditions>
<action type="Redirect" url="http://blogs.mycompany.com{C:1}" />
</rule>

How to rewrite the index.php of Codeigniter on Windows Azure

How to remove index.php in codeigniter on Windows Azure and IIS?
Can I rewrite the URL for the index.php of Codeigniter without a particular module?
You can add rewrite rules in your web.config file. Add the following to the system.webServer section:
<rewrite>
<rules>
<rule name="Rule" 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/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Create a file name web.config in wwwroot
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You can also implement other rewrite rules like
<rule name="a rule">
<match url="^xxx/(.*)/(.*)-(.*)\.xxx" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="controller/method/{R:3}" />
</rule>
with one condition, is to change $config['url_protocal']='PATH_INFO'; in config/config.php this will tell URL rewrite module to use re-writed URI instead of original URL, otherwise you will have 404 page not found problem.

IIS Rewrite Rule how to check requesturl + .php file is exists or not in rule

i want to check that file with requestedurl + .php is exists or not.
in apache i can do this with RewriteCond %{REQUEST_FILENAME}.php -f
so that it can rewrite my request test.com/login to test.com/login.php
i want to do same with iis rewrite rule.
i have tried with following.
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}\.php" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
<rule name="Imported Rule 2">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="allpages.php" />
</rule>
</rules>
</rewrite>
but it doesnt works.
thanks in advance for help
Change {REQUEST_FILENAME}\.php to {REQUEST_FILENAME}.php in first rule.
Further there is no need to check if requested URL exists as directory.
To rewrite 'test.com/login' to 'test.com/login.php' only if login.php exits, use:
<rule name="Rewrite to PHP">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}.php" />
</rule>
Tested

Resources