How to use web.config with two domains - web-config

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>

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>

In IIS, how can I forward all my URLs to a non-www, https, and no file extension without having too many redirects

I have gone through many similar questions in Stack Overflow, but I have not been able to find one that helps me to have all three of these re-direct rules work together.
I am trying to forward all of my URLs to this format:
https://example.com/page
I need the https, I don't want the www, and I don't want the html or aspx extensions to be visible. Here is what I have so far. Chrome says that I have too many redirects, how do I consolidate these rules?
<rewrite>
<rules>
<clear />
<rule name="RewriteHTML">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.html" />
</rule>
<rule name="Redirect www to non-www" enabled="true" stopProcessing="true">
<match url="(.*)\.html$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://example.com/{R:1}" redirectType="Permanent"/>
</rule>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)\.html$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
</rule>
<rule name="RemoveExtension" stopProcessing="true">
<match url="(.*)\.html$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I finally figured it out after playing around with patterns and rule orders, and the stopProcessing command, etc. No more redirect loops! I actually figured out what I was asking and more.
Removes index.html from root domain
Redirects www to non-www
Removes trailing slashes
Makes the URL always lowercase
Redirects http:// to https://
Enables URL to work without .html extension
Redirects to URL without .html extension
My code:
<rules>
<!-- index.html Redirect -->
<rule name="index.html Redirect" enabled="true">
<match url="^(.*\/)*index\.html$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_METHOD}" negate="true" pattern="^POST$" />
</conditions>
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<!-- Redirect WWW to non-WWW -->
<rule name="Redirect WWW to non-WWW" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://example.com/{R:1}" />
</rule>
<!-- Remove Trailing Slash -->
<rule name="Remove Trailing Slash" enabled="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
<!-- Make URL Lower Case -->
<rule name="Make URL Lower Case" enabled="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
<!-- Redirect To HTTPS -->
<rule name="Redirect To HTTPS" enabled="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<!-- Redirect To URL With No Extension -->
<rule name="Redirect To URL With No Extension" enabled="true">
<match url="(.*)\.(html)" />
<action type="Redirect" url="{R:1}" />
</rule>
<!-- Rewrite URL For No Extension -->
<rule name="Rewrite URL For No Extension" enabled="true" stopProcessing="false">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.html" />
</rule>
</rules>
Here is what the rules look like in the IIS URL Rewrite module:

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>

Redirection using web.config on wordpress website

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>

Zend MVC query string rewrite

Background : I am using IIS 7 (Windows 2008) and Zend Framework
What I am working on is rewriting a link site/blog?Id=1 to site/blog/1
Can anyone tell me why this doesn't work?
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^blog$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^Id=([^=&]+)$" />
</conditions>
<action type="Redirect" url="blog/{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^blog/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="blog?Id={R:1}" />
Thanks in advance.
Use this instead as mention in zend doc
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}"
matchType="IsFile" pattern=""
ignoreCase="false" />
<add input="{REQUEST_FILENAME}"
matchType="IsDirectory"
pattern="" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^.*$" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
src
Try the following code in your .htaccess file:
RewriteRule ^blog/([0-9]+)/?$ blog?id=$1 [NC,L] # Handle requests