301 redirect on IIS. Redirect non-www to www - iis-6

I ought to redirect my website from non-www to www on IIS 6. e.g if I enter domain.com in the url, it has to redirect to www.domain.com for SEO optimization.
I followed the video "http://www.youtube.com/watch?v=PYxabNrIMQ4" for creating my rewrite rule. And I made it as below
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:0}" />
</rule>
</rules>
</rewrite>
But it is not working as expected. Help me out to find the solution.
Note:
My Visual studio shows warning like "The element 'system.webServer' has invalid child element 'rewrite'".
I believe it doesn't make any problem.

According to this video you can redirect using the IIS Manager UI. Make sure you have a second site for the non-WWW version, with the same "Location" as the WWW version of your site; when creating it, be sure to specify your non-WWW domain for the "Host Header" field.
After creating it, right-click the site and go to Properties. Disable logging if you're so inclined (probably not needed because you'll be redirecting anyways), then go to the "Home Directory" tab. Now remove the Application by clicking the appropriate "Remove" button, since it's not used for redirection. Next, select the "A redirection to a URL" radio button, be sure to check "The exact URL entered above" and "A permanent redirection for this resource".
Lastly, in the "Redirect to" field, enter your full WWW url followed by $S$Q (i.e. http://www.example.com$S$Q) -- the $S$Q are important to capture any path and query string the client might send, so if the user goes to http://example.com/foo/bar.html they will be appropriately redirected to http://www.example.com/foo/bar.html instead of just http://www.example.com/ . Click Apply and OK, and your redirection should be set!

Does this works ? remember to add in the root web.config
<rules>
<rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain.com" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:0}" />
</rule>
</rules>

Related

Duplicate, submitted URL not selected as canonical

I have my canonical tag URL as http://www.example.com/ in HTML header and also same in sitemap.xml. my host has enabled SSL and previously in search console I have been added HTTPS version of my address and three green check marks showed and was okay, then because SSL certificate was low quality some mobile phones couldn't reach it and I disabled SSL, but now Google selects HTTPS version of my address.
here is web.config
<rules>
<rule name="Redirect http://example.com to http://www.example.com HTTP" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*"></match>
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$"></add>
<add input="{HTTPS}" pattern="off"></add>
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" appendQueryString="true"></action>
</rule>
</rules>
its HTTPS version address goes to site control panel and certainly isn't same as HTTP version so that it chooses that one. any suggestions?

Unable to convert IIS web.config URL Friendly to .htaccess mod_rewrite

I'm migrating a web application from a Windows (IIS) server to a Linux (Apache) and I have been a few days trying to adapt the application, configs, etc. for Linux/Apache.
Everyting is working except the url friendly I was using with Windows/IIS. And I don't know if this is actually a URL Friendly, a simple redirect or anything else.
This is what I want:
I have a 'app.php' file which is like the main application 'index', and shows different 'pages' depending on the old/ugly url parameters:
https://example.com/app.php?qpage=5&qsubpage=2&action=new
Instead of writting this, I want to use friendly urls like this:
https://example.com/section5/?qsubpage=2&action=new
(Please notice that the second and third parameters 'qsubpage' and 'action' are optional!)
Ok, with IIS and this lines in web.config, it works fine:
<rewrite>
<rules>
<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="app.php?qpage={R:1}" />
</rule>
</rules>
</rewrite>
Then, in 'app.php' file I get the current URI and (optional) parameters to show one content or another.
However, I can't reach to get it working with .htaccess.
This is what I have know. It works fine only if there is just one parameter:
If I go to...
https://example.com/section5
...it shows the correct 'page' correctly.
However, if I go to...
https://example.com/section5/?qsubpage=2
or
https://example.com/section5?qsubpage=2
...'qsubpage' is ignored.
If I go to
https://example.com/section5&qsubpage=2
...I get a '404: url not found' error (however it works in Windows)
This is my .htaccess rule:
RewriteEngine On
RewriteRule ^([A-Z-a-z-0-9]+)/?$ simplygest.php?qpage=$1&qsubpage=$2 [L]
I have tried some online mod_rewrite generators and even web.config to .htaccess converters online with no success.
Thanks!

URL Rewrite Rule: HTTP to HTTPS Not Working in IIS 8 2016 Server: ERR_INVALID_REDIRECT

I installed a godaddy SSL certificate. All these urls work in the browser:
"park.mydomain.com", "http://park.mydomain.com", "https://park.mydomain.com". The first two show unsecured and the last secured. In the bindings I have two entries. One [https park.mydomain.com port 443] and the other is [http park.mydomain.com port 80]. I installed URL rewrite and added a rule from this link: here. Now, if I type the first or the second url the browser says not found ERR_INVALID_REDIRECT. Only the third one that is https:park.mydomain.com works. If I disable the rule all three work again. What is wrong ? Why is it not redirecting ? The 2016 server with IIS is hosted in azure
<rewrite>
<rules>
<rule name="http_https" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_POST}/{R:1}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
The redirection was setup correctly. The problem was on the type of certificate that I had installed, that was for one domain only.

URL should hit https instead of http

I am running a Windows Server, where i have hosted a site.
Now i have done the Binding with the SSL certificate for the site. But every time i hit the website URL, it goes to http instead of https. Althoough i have binded http & https with the SSL certificate.
Example -
when i try to hit abc.com
it goes http://example.com
instead of
https://example.com
Do i have to do anything more which can help me to fix this issue.
so everytime i try to visit
example.com
i will visit
https://example.com
Do anyone knows a way to fix this issue !
You need to add a redirect to make sure all traffic gets redirected, something like below. Make sure you have the URL rewrite module installed.
<rule name="HTTPS force" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

IIS URL Rewrite rule not being triggered

I am pretty sure that I have my WCF URL Rewrite Rule coded correctly in my Web.config file:
<rewrite>
<rules>
<rule name="RemoveSVC" stopProcessing="true">
<match url="MyWebSvc/([a-zA-Z]+)-svc/(.*)" />
<action type="Rewrite" url="MyWebSvc/{R:1}.svc/{R:2}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
The rewrite rule seems to be working in the "Test pattern..." widget. For instance:
http://localhost/MyWebSvc/thinga-svc/majigs
gets correctly mapped to:
{R-1} thinga
{R-2} majigs
And I would like the URL to be re-written to:
http://localhost/MyWebSvc/thinga.svc/majigs
Seems simple enough, however, when I try to test the URL from a browser:
http://localhost/MyWebSvc/thinga.svc/majigs
works, but
http://localhost/MyWebSvc/thinga-svc/majigs
does not appear to be re-written, and I get a 404 response code. Do I have to configure the rule to be triggered with some other setting?