force redirect non www url to www - wordpress

I'm going straight to the point here.
I actually install a wordpress site on a windows server.
however, when I visit the site on my browser using "sample.com.ph" it shows me The connection has timed out however when I visit the "www.sample.com.ph" it work just fine.
Here's my web.config file.
I am really new to this so please bear with me.
what I want is to force it to redirect to a www..
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress: http://www.sample.com.ph" 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

IIS URL Rewrite to querystring parameter

I need to capture requests to folders that aren't file folders to be redirected to a default page with the requested path as the querystring.
For example, if the user requests
www.mysite.com/IT
I want it to redirect to
www.mysite.com/default.aspx?q=IT
However, if they request a page that is in a real sub-folder, that shouldn't be redirected. For example, requests to www.mysite.com/projects/new.aspx shouldn't try to do any re-directions as it's a physical folder and file in the site.
Use the IIS Rewrite module and the set it up in the web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirector" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{PATH_INFO}" pattern="/*" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/default.aspx?q={PATH_INFO}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You could define a 404 error page that would redirect to your default page with the "q=" that you desire

How do I negate login.aspx in the web.config with Wordpress

We have recently created a Wordpress site which will be hosted on a Windows 2012 Server. The server is currently serving compiled code of which one of the URL's it uses is login.aspx.
When we add the Wordpress site and enable permalinks, we get the default Wordpress page instead of login.aspx.
We have unsurprisingly narrowed it down to the web.config rewrite rule.
<rewrite>
<rules>
<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>
I'm sure we have to negate the login.aspx page some how but I'm not sure how to do it. This has to work as a single site for now.
All I needed to do was add in the following:
<add input="{URL}" negate="true" pattern="*.aspx" />

Adding code to web.config to hide my page extensions

I have this web.config file and i want to add a code to it that will hide the .asp of a page in my website called "users.asp" . please how do i do it
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
Obviously you need the URL rewrite module installed, and you need IIS7 or above, this won't work on IIS6
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^users/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="users.asp" />
</rule>
</rules>
</rewrite>
Recommended reading:
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module

IIS7 URL Rewrite for short urls

I've been working on a small link length supressor site and can't seem to figure it out on IIS7. I'm used to working on isapi rewrite and mod_rewrite.
The following scenario is active:
Lets say I have test.com, thats the main domain. The domain should process all files normally. But when the /.* isn't a directory nor a file, it should send it to redirect.asp?text=(.*).
This is what my web.config looks like
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="YOURLS 1" stopProcessing="true">
<match url="^([0-9A-Za-z-]+)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="redirect.asp?test={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
Can't see much wrong with your rule, except maybe that you use test (with an 's') as the query string parameter in your web.config but in your text you say that it should be text. A typo or maybe that's the reason it's not working?
<action type="Rewrite" url="redirect.asp?text={R:1}" appendQueryString="false" />
It seemed to have to do with a wrong version of the URL rewriter. I installed the latest 2.0 and it was fixed!

URL rewrite - web.config error

I am getting the following error when i run my .aspx page.
Error Code0x8007000d
The configuration section 'rewrite' cannot be read because it is missing a section declaration
I have a simple v.aspx page which has the following code:
Response.Write(Request("q"))
My hosting server as IIS 7 installed with URL rewrite feature enabled (that's what they claim)
My web.config file has the following lines under :
Note: The node has blue squiggly lines under it
<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="v.aspx?q={R:1}" />
</rule>
</rules>
</rewrite>
I have searched stackoverflow but did not find a solution.
May be someone found a solution.
TIA
Make sure your <rewrite> is enclosed in the <system.webServer></system.webServer> section.
<configuration>
<system.webServer>
<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="v.aspx?q={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Install the URL Rewrite module http://www.iis.net/download/URLRewrite and that should be sorted. It fixed my problem
The rewrite section in system.webServer is supported in IIS7, but not IIS6. The error is likely caused by deploying this site to a server that's only running IIS6.

Resources