ISAPI PHP REWRITE - mod-rewrite

A friend is having me figure out a way to modrewrite on his windows server. He is running IIS 6 and Isapi is about the only thing I can find. I am not familiar with it and have read some of the documentation, but can't quite wrap my head around it. He is wanting to rewrite these URLS to make them clean
www.domain.com/cat.php?CTGID=####
and
www.domain.com/pp.php?ID=##
How would I go about rewriting these two URLS to make them Clean in ISAPI. I have installed it on the Windows Server and do I put these rules in IISF.ini in his website folder or put these codes in the master IISF file? Any Help would be greatly appreciated!

Rewrite rules go in a web.config file or in the ApplicationHost.config.
As described in http://learn.iis.net/page.aspx/465/url-rewrite-module-configuration-reference/
Examples
<rewrite>
<rules>
<rule name="Force WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
<rule name="Redirect from blog">
<match url="^blog/([_0-9a-z-]+)/([0-9]+)" />
<action type="Redirect" url="article/{R:2}/{R:1}" redirectType="Found" />
</rule>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.aspx?id={R:1}&title={R:2}" />
</rule>
</rules>
</rewrite>

For IIS, if the ISAPI_Rewrite module is installed, $_SERVER["IIS_UrlRewriteModule"] is set and contains the version number of the module. So you can check for the existence of this server variable.

Related

Enable htpps for a website hosted in windows server

Having the SSL certificate supposedly implemented on the server, what's the next step to have "https//" at the beginning of the URLs?
Thanks for the overwhelming help. I managed to resolve my problem and was actually very simple. I had to create a web.config file and copy paste the next code
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Force HTTPS" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.example.es/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
And after that, replace the url with the one from your own web. Simple but if you donĀ“t have any knoledge on the matter is actually very frustrating

Rewrite rule for windows server + IIS and Cakephp 3.x

I want to deploy my site to Windows hosting from linux. On Linux server everything working as expected. but few things are not working on windows server.
Please let me know what changes i need to do in web.config
My file system is:
-src
-webroot
--css
--about.html
--index.php
--contact.php
Now how i can access about.html directly http://www.example.com/about.html and similarly for other php files too.
these are rule i am using for now:
<rewrite>
<rules>
<rule name="Exclude direct access to webroot/*"
stopProcessing="true">
<match url="^webroot/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets(img, css, files, js, favicon)"
stopProcessing="true">
<match url="^(assets|font|fonts|img|images|css|files|js|favicon.ico)(.*)$" />
<action type="Rewrite" url="webroot/{R:1}{R:2}"
appendQueryString="false" />
</rule>
<rule name="Rewrite requested file/folder to index.php"
stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="index.php"
appendQueryString="true" />
</rule>
</rules>
</rewrite>

URL Rewrite rule in .NET to force www but ignore http(s)

I'm looking to set up a rewrite rule in my web.config file which forces URLs to use the 'www' sub-domain. This is done like so:
<rules>
<rule name="Add WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://www.{C:0}{PATH_INFO}" redirectType="Permanent" />
</rule>
However, the project is running multiple websites on multiple domains, some of which use SSL and some don't.
The code above hard-codes http:// into the redirect. What I'm looking to do is to abstract this such that the http or https protocols are maintained during the redirect without being hard-coded.
Some examples of the desired results are:
http://olddomain.com > http://www.newdomain.com
https://someolddomain.com > https://www.somenewdomain.com
Many thanks.
I found a reference which explains one approach in doing this. It uses rewrite key/value pairs as a 'variable' in the action url, as (as far as I can find out) there's no way currently to grab the protocol as a native variable inside the rule.
The rule has been modified as follows, which should do what's required:
<rewrite>
<rules>
<rule name="Add www maintain https" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" />
</conditions>
<action type="Redirect" url="{MapSSL:{HTTPS}}www.{C:0}{PATH_INFO}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapSSL" defaultValue="http://">
<add key="ON" value="https://" />
<add key="OFF" value="http://" />
</rewriteMap>
</rewriteMaps>
</rewrite>
There's also another reference which includes this amongst alternative ways to achieve the same thing.

Routing all requests for different domains to different folders on the same root

I posted a question up yesterday basically I have a single plan with winhost and I want to be able to have multiple domains (that are all pointed at my root) go to different subfolders and in these sub-folders I host different MVC apps. A very helpful chap took me most of the way but (and I know its lame how difficult im finding this) but I really cannot work out how to do the final peice...
The IIS config...
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect if producerpte" stopProcessing="true">
<match url="^producerpte/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Rewrite to sub folder">
<match url="^.*$" />
<action type="Rewrite" url="producerpte/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
works brilliantly. When I now go to http://www.producerpte.co.uk I can see my site in the subfolder but the url looks like its on the root. However I also want to try and host my girlfriends site so I have tried multiple combinations but I just cannot seem to add rules that will work for both sites...I know I need to add two more rules like this...
<configuration>
<system.webServer>
<rewrite>
<rules><!--first site-->
<rule name="Redirect if producerpte" stopProcessing="true">
<match url="^producerpte/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Rewrite to sub folder producerpte">
<match url="^.*$" />
<action type="Rewrite" url="producerpte/{R:0}" />
</rule>
<!--second site-->
<rule name="Redirect if samyoga" stopProcessing="true">
<match url="^samyoga/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Rewrite to sub folder samyoga">
<match url="^.*$" />
<action type="Rewrite" url="samyoga/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Whatever it is about the last rule I just cant get it to route. If I use it then when I go to Samyoga.co.uk I end up at Samyoga.co.uk/producerpte ?????
I tried matching the wildcard in the second rule (for each site) it just doesnt work at all then.....

IIS 8.0 Directory HttpRedirect

Is there a way in IIS to redirect the following request:
http://mysite/report1/img/logo.png to http://mysite/myapplication/report1/images/logo.png for ALL images in the img directory without having to explicitly map them individually?
Additional requirement- I have THOUSANDS of reports on a drive mapped to the 'report1' virtual directory- each with their own 'img' directory- so there is no reasonable way to use IIS manager to map those directories individually either.
I'm looking to see if there is some way to add a wildcard (or other) HttpRedirect in the IIS server web.config file to correctly map all the images for all the reports. I tried:
<add wildcard="*res/img/" destination="/reporter/content/images/reportimages" />
But that seemed to have no effect.
EDIT: Some more research shows that using the URL Rewrite module might work... but so far I haven't gotten it to work.
My rule looks like this (in web.config):
<rules>
<rule name="Redirect rule1 for ImageRedirect">
<match url=".*" />
<conditions>
<add input="{ImageRedirect:{REQUEST_URI}}" matchType="Pattern" pattern="/res/img/(.+)" ignoreCase="true" negate="false" />
</conditions>
<action type="Redirect" url="{HTTP_HOST}/reporter/content/reporterimages/{C:1}" appendQueryString="false" />
</rule>
</rules>
You were on the right track using the URL Rewrite module.
The most simple rule in your case would be:
<rule name="Rewrite images" stopProcessing="true">
<match url="^/report1/img/(.+)$" />
<action type="Rewrite" url="/myapplication/report1/images/{R:1}" />
</rule>
It does check if the requested url matches ^/report1/img/(.+)$ and if yes, trigger a rewrite to your new folder.
If you want to use a Redirect instead:
<rule name="Redirect images" stopProcessing="true">
<match url="^/report1/img/(.+)$" />
<action type="Redirect" url="/myapplication/report1/images/{R:1}" />
</rule>
(If you don't specify it, by default a Redirect is permanent (301))

Resources