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
Related
Why when i convert .htaccess automatically with IIS web.config via IIS Manager > Rewrite URL this show me 404 error
How to convert this manually to web.config?
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(install)($|/) - [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This is the result using IIS Manager (web.config)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(install)($|/)" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="/app/webroot/" />
</rule>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="/app/webroot/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
What's the Sub-status code of 404 error? Because 404.0 and 404.19 is different error. You could find it in C:\inetpub\logs\LogFiles.
It looks like the rule has been transformed correctly.
Rule1 will scan incoming URL domain.com/install/ or domain.com/install and prevent these URL from being rewritten.
Rule2 will rewrite domain.com to domain.com/app/webroot/
Rule3 will rewrite Any incoming rule for example. domain.com/a.aspx to domain.com/app/webroot/a.aspx.
So are these rules achieve your requirement?
To promise rewrite could be processed without ensure
1.Please ensure the request has been delivered to your IIS server. Sometimes networking issue would route the request to another server and return 404 error.
2.Please ensure the target URL like domain.com/app/webroot/ or domain.com/app/webroot/(.*) can be accessed without any issue.
I have a symfony2 project developed on a linux server and have migrated it (unfortunately!) to a windows server for reasons outside of my control. This all works as it should except for the url rewriting. I tried using the IIS URL Rewrite Module but it failed when converting most of the rules (and stupidly i didn't save a list of which ones it failed on).
It mostly works fine but the app.php is still present at the start of all urls which it shouldn't be. So the urls are domain.com/app.php/correct/path when they should be domain.com/correct/path
Unfortunately i rarely use windows servers and am not good at the web.config syntax so if anyone could suggest what is missing to remove the app.php from the start of all urls on the windows server then that would be greatly appreciated!
The original .htaccess file is:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
The converted web.config file is currently:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url=".?" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Thanks very much!
Dave
Have just had this same issue while setting up symfony2 on a Windows server using IIS7.5.
The trick is to go into you web site management section. Look for 'url rewrite', look for 'Import Rules'(somewhere on the right). Then on the new dialogue browse for your .htaccess file in 'SymfonyProject/web/' by default. IIS will throw an error for the trailing slash rule so delete that (Everything seems to work fine without it) and press apply. Viola no app.php.
Be sure to add app.php to your list of default pages also.
I did the above using the standard htaccess file shipped with Symfony2.
EDIT As Requested Below
In the Import Dialog I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / <-This line needs deleting as IIS states "This directive was not converted because it is not supported by IIS: RewriteBase "
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
So the begining of my web.config looks like this:
<defaultDocument enabled="true">
<files>
<add value="app.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="app.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Also I have set my web directory as my root directory.
Hope this helps.
Doug.
I know this is an old question but today i had the same problem and i searched everywhere and took me a lot of time to fix it by replace the .htaccess file in web directory to web.config file with this content hope this will help some one .
<?xml version="1.0"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="app.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Symfony Front Controller" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="app.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I had same issue on a Plesk Linux to Plesk Windows migration. I removed the htaccess file and edited the default web.config file according to previous comments.
In my case, I just needed to change the "app.php" with "index.php" and then it works. This is the content of my web.config file
Hope it will helps !
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Symfony Rewrite" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<tracing>
<traceFailedRequests>
<clear />
</traceFailedRequests>
</tracing>
</system.webServer>
</configuration>
i try to put my .htaccess (that work on linux server) in my azure end not work.
I think the issue is that I had to use web.config structure, so I try also this, but now http return 500.
My .htaccess is:
RewriteCond %{REQUEST_URI} r\/([\w\d]+)?\/([\w\d]+)$
RewriteRule r\/([\w\d]+)?\/([\w\d]+) php/Router.php?called_class=$1&called_method=$2 [L,QSA]
I've solved.
This is web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rule1" stopProcessing="true">
<match url="r\/([\w\d]+)?\/([\w\d]+)" />
<action type="Rewrite" url="/php/Router.php?called_class={R:1}&called_method={R:2}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I'm having a hard time rewriting the following RewriteCond into web.config alternative and would appreciate any help.
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in_.*$
Using URL Rewrite module in IIS 7, rewrite rules with conditions would look something like this:
<rules>
<rule name="something">
<match ... />
<conditions>
<add input="{HTTP_COOKIE}" pattern="^.*wordpress_logged_in_.*$" />
</conditions>
<action ... />
</rule>
</rules>
You can also use the URL Rewrite GUI interface in a local IIS 7 install to help build your rewrite rules, and then open the corresponding web.config to see how it should look.
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/