Redirection using web.config on wordpress website - redirect

I have issue about redirection using web.config . It is word-press website hosted on godaddy.com. Server IIS 7.0 It is window server.
I want redirect from old html page to new wordpress page.
Example:
http://www.dakshadesign.com/Ecommerce_Web_Design.html to http://www.dakshadesign.com/ecommerce-website-design-web-development-company-india/
Resloved now
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to dakshadesign.com" stopProcessing="true">
<match url="^Ecommerce_Web_Design.html$" />
<action type="Redirect" url="http://www.dakshadesign.com/ecommerce-website-design-web-development-company-india" appendQueryString="false" />
</rule>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Related

How can I exclude specific subdomains from redirect to HTTPS in web.config?

I'm working on an MVC project, and I have the following working rule in my web.config, but it's redirecting all the subdomains to https. What I would like to do is to exclude some specific subdomains. For example, I need to redirect "mywebsite.com" and "www.mywebsite.com", but not "test.mywebsite.com" or "beta.mywebsite.com". The excluded subdomain should remain as "http://test.mywebsite.com" and "http://beta.mywebsite.com" without being redirected to https. How can I do that? Here's my rule in web.config:
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{REQUEST_URI}" negate="true" pattern="^/\.well-known/pki-validation/(.*)$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="true" />
</rule>
I used to have a similar configuration had used a rule along this line:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="redirect to https2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^subdomain\.example\.com$" negate="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="false" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{URL}" redirectType="Found" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

IIS got ERR_TOO_MANY_REDIRECTS on rewrite rule

I'm trying to create an IIS rule to redirect mobile users to the mobile site.
The main site (desktop version) is in the root route ('/'), and the mobile site is in the route '/mobile'
I created this IIS rule, but when I try it in desktop it's work well, but in mobile, I got an error ERR_TOO_MANY_REDIRECTS
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Mobile" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="true"/>
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-Device-User-Agent}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-OperaMini-Phone-UA}" pattern="midp|mobile|phone" />
</conditions>
<action type="Redirect" url="mysiteurl/mobile" appendQueryString="false" />
</rule>
</rewrite>
</system.webServer>
</configuration>
It is happening because your rule is also matching all mobile URLs. You need to exclude mobile URLs from your rule. This rule will work for you:
<rule name="Rewrite Mobile" enabled="true" stopProcessing="true">
<match url="mobile(.*)" negate="true"/>
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-Device-User-Agent}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-OperaMini-Phone-UA}" pattern="midp|mobile|phone" />
</conditions>
<action type="Redirect" url="/mobile" appendQueryString="false" />
</rule>

HTTPS redirect in web.config leads to ERR_TOO_MANY_REDIRECTS

I'm trying to add a redirection rule in web.config to only serve my webpage in HTTPS and no HTTP at all; so far I've used this ruleset (together with my 404 redirect):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
<directoryBrowse enabled="false" />
<httpErrors errorMode="Custom" existingResponse="Auto">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="index.php" responseMode="Redirect" />
</httpErrors>
</system.webServer>
</configuration>
However, this leads to ERR_TOO_MANY_REDIRECTS; what is wrong with this web.config to cause this? It seems to work for other users.
I have already tried suggestions in these posts; Redirect loop when forcing HTTPS, URL Rewrite causing redirect loop, this blog and this blog.
Maybe I came here a bit late, but the following Rewrite rule helps to solve the redirection error:
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^example\.com$" />
<add input="{SERVER_PORT}" pattern="^80$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

How to use web.config with two domains

I have this cenario:
In my principal domain i have my blog under permalink wordpress
In an folder /xyz i have an other domain abc.com.br pointed.
How to construct rules to both.
This is my actualy web.config. only work with blog.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard" 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="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>

IIS 7.5 - redirect url /index.php/* to /*

I have php a website set up under IIS 7 using cakePHP. It was running for quite a while using not-so-pretty urls of the form /index.php/[controller]/[action]/[etc]. Long enough for people to have bookmarks and Google to index everything. I've now fixed the web.config so that the urls that get used are of the from /[controller]/[action]/[etc], bypassing the index.php in the url (internally it all goes to the same place).
The problem is, that if you visit one of the links in the older format, the page still technically works, but css / images / etc aren't being loaded and it looks ugly. Is there a simple way to redirect from the /index.php/* format to the new /* format?
The following is my existing web.config performing the required rewrites:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect static resources" stopProcessing="true">
<match url="^(ico|img|css|files|js)(.*)$" />
<action type="Rewrite" url="app/webroot/{R:1}{R:2}" appendQueryString="false" />
</rule>
<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>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="/" />
</rule>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="/{R:1}" />
</rule>
<rule name="Imported Rule 4" 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>
I worked out what I was missing. In the redirect rule, I match on /index.php/* but I didn't realize you can add the matched string into the destination using $0, $1, $2, etc. Also of note, the exactDestination="true" is necessary, otherwise it redirected /index.php/[controller]/[action]/[etc] to /[controller]/[action]/[etc]/index.php/[controller]/[action]/[etc]
I just had to add the following section to the top of the web.config (in the <system.webserver> section, before the <rewrite> section:
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Permanent">
<add wildcard="/index.php/*" destination="/$0" />
</httpRedirect>