Replicate mod-proxy behavior in IIS - iis

I need a http proxy server that redirects requests coming from mydomain.com to http://localhost:8080
Apache web server does this with mod_procy and mod_proxy_http with the following configuration
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot D:/tmp/iis
DirectoryIndex index.html index.php index.jsp
<Proxy *>
Order Allow,Deny
Allow from all
</Proxy>
ProxyRequests On
ProxyVia On
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
My server is a windows machine and I’d like to use IIS (Internet Information Services) instead I tried the following IIS configuration:
binding
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRuleForReports" stopProcessing="true">
<match url="(/.*)" />
<action type="Rewrite" url="http://localhost:8083/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
IIS rewrites the URL but doesn’t forward the request to another server as mod_proxy does in Apache
Is it possible to replicate Apache behavior in IIS? In that case what is the right server configuration?

If you have a useful Apache proxy rule, you can import it into IIS. IIS will auto generate url rewrite rule. Refer to this article.

Related

how convert htaccess deny rule to IIS url rewrite rule

I am converting .htaccess file to rewrite rules in IIS to convert from http to https,
all the rules are being converted which starts with RewriteCond but deny from all is not converted
I want to convert this htaccess rule to IIS rewrite rule
<Files ~ "\.log$">
Deny from all
</Files>
Is there any other way to convert it? or I doing something wrong.
to convert this rule you could use the request filtering feature of iis or URL rewrite.
<configuration>
<security>
<requestFiltering>
<fileExtensions>
<add fileExtension=".log" allowed="false" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
</configuration>
using url rewrite rule:
<rule name="Protect files and directories from prying eyes" stopProcessing="true">
<match url="\.log$" />
<action type="CustomResponse" statusCode="403" subStatusCode="0" statusReason="Forbidden" statusDescription="Access is forbidden." />
</rule>
for more detail please refer this link:
https://learn.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig#request-filtering

remove www from web address

I'm running php on IIS 8.0.
when I enter the site address with www server returns IIS Error 500. with out www everything is OK.
How can I automatically remove www from adress.
you can use url rewrite module
add this code to web.config and replace domain.tld with your domain name
<rule name="Remove www" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://domain.tld{PATH_INFO}" />
</rule>
There are multiple ways to redirect your site to domain only,
1) using DNS server, in DNS you can redirect your visitors to domain only,
2) using IIS config file -> C:\Windows\System32\inetsrv\config.
You don't want to simply redirect because you will have to do that for every page and subdomain. My code will auto strip the www. for you.
.htaccess code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
If you want to fix you DNS issue just add a 'A' record with www.yourwebsite.com

FollowSymlinks .htaccess Rewrite Rule 404 Error

My real URL is:
www.mysite.com/site/index.php
I need:
www.mysite.com/home.html
I write in the .htaccess:
Options +FollowSymlinks
RewriteEngine On
RewriteRule (.*)/home.html$ /site/index.php
But go to 404 Error
Any help?
Tk.
UPDATE:
Have any effect that the domain is actually: www.my-site.com ??
UPDATE:
I save in www.my-site.com and change for this:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^home\.html$ site/index.php
</IfModule>
But no work.
The pattern part of the RewriteRule directive matches on the path of the request (eg. /my/request/), the host and query string is not included. Also note that in a .htaccess context the leading slash is not included in the pattern.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^home\.html$ site/index.php
in my server, i changed on httpd.conf in Apache
AllowOverride None to AllowOverride All
And Work it!
You said in the comments:
The file .htaccess is save in www.mysite.com/site/
This means, with the current pattern you can access www.mysite.com/site/anything/home.html which will be rewritten to www.mysite.com/site/site/index.php
You should put the .htaccess in the document root and, as already suggested, remove this part from the pattern: (.*)/
This site is hosted by godaddy.com, the server run in Windows over IIS, so, the rule have to be write in a web.config file.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^home\.html$" ignoreCase="false" />
<action type="Rewrite" url="site/index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Unbelievable!!

Apache .htaccess rewrite rule to IIS web.config rule

I am moving a PHP application from Apache to IIS server. I am trying to translate the following .htaccess rule:
RewriteEngine On
RewriteRule ^(.*)$ public/$1?%{QUERY_STRING} [QSA,L]
It simply redirects all requests (as well as query string) to public subdirectory.
I have tried something like the following in web.config file-
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Root Hit Redirect" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/public/index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
But it keeps falling into redirect loop. What should be correct web.config rule in this case?
Managed to solve this by importing rules in IIS.
http://akrabat.com/winphp-challenge/zend-framework-url-rewriting-in-iis7/

apache mod_rewrite mod_proxy subdomain to dir

i have a domain www.example.com as front end, and i have many servers having front end servers
like games.example.com
what i want www.example.com in the background will access games.example.com
so games.example.com = www.example.com/games
this code will handle any access to directory /games will access the backend server
<Location /games>
ProxyPassReverse games.example.com
ProxyPassReverse games.example.com:80
RewriteEngine On
RewriteRule games(.*)$ http://games.example.com/$1 [QSA,P,L]
</Location>
it's working but
its giving me this url
www.example.com/web/login.php which will raise 404 page not found how can i append word games in any URL by being like this www.example.com/games/web/login.php ?
<Location /games>
ProxyPassReverse games.example.com
ProxyPassReverse games.example.com:80
RewriteEngine On
RewriteRule games(.*)$ http://games.example.com/games/$1 [QSA,P,L]
</Location>

Resources