Acquia Drupal's web.config file

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
chicagomom's picture

At the risk of talking only to myself once again, I thought it might be useful to someone to put up the web.config file generated by the Web Platform Installer's Acquia Drupal installation, since if you're not using the WebPI you need to generate this yourself. It looks like it covers pretty much everything in the standard .htaccess file. Anyone know if there's anything it doesn't do? Anyway, here it is:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
  <!-- Don't show directory listings for URLs which map to a directory. -->
    <directoryBrowse enabled="false" />

    <!--
       Caching configuration was not delegated by default. Some hosters may not delegate the caching
       configuration to site owners by default and that may cause errors when users install. Uncomment
       this if you want to and are allowed to enable caching
     -->
    <!--
    <caching>
      <profiles>
        <add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
        <add extension=".html" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="14:00:00" />
      </profiles>
    </caching>
     -->

    <rewrite>
      <rules>
        <!-- rule name="postinst-redirect" stopProcessing="true">
          <match url="." />
          <action type="Rewrite" url="postinst.php"/>
        </rule -->

        <rule name="Protect files and directories from prying eyes" stopProcessing="true">
          <match url=".(engine|inc|info|install|module|profile|test|po|sh|.
sql|postinst.1|theme|tpl(.php)?|xtmpl|svn-base)$|^(code-style.pl|Entries.|Repository|Root|Tag|Template|all-wcprops|entries|format)$" />
          <action type="CustomResponse" statusCode="403" subStatusCode="0" statusReason="Forbidden" statusDescription="Access is forbidden." />
        </rule>
        <rule name="Force simple error message for requests for non-existent favicon.ico" stopProcessing="true">
          <match url="favicon.ico" />
          <action type="CustomResponse" statusCode="404" subStatusCode="1" statusReason="File Not Found" statusDescription="The requested file favicon.ico was not found" />
        </rule>
                <!-- To redirect all users to access the site WITH the 'www.' prefix,
                http://example.com/... will be redirected to http://www.example.com/...)
                adapt and uncomment the following:   -->
                <!--
        <rule name="Redirect to add www" stopProcessing="true">
          <match url="^(.
)$" ignoreCase="false" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^example.com$" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="http://www.example.com/{R:1}" />
        </rule>
                -->
                <!-- To redirect all users to access the site WITHOUT the 'www.' prefix,
                http://www.example.com/... will be redirected to http://example.com/...)
                adapt and uncomment the following:   -->
                <!--
        <rule name="Redirect to remove www" stopProcessing="true">
          <match url="^(.)$" ignoreCase="false" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^www.example.com$" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="http://example.com/{R:1}" />
        </rule>
                -->
        <!-- Rewrite URLs of the form 'x' to the form 'index.php?q=x'. -->
        <rule name="Short URLS" stopProcessing="true">
          <match url="^(.
)$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>

    <!-- httpErrors>
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="/index.php" responseMode="ExecuteURL" />
    </httpErrors -->

    <defaultDocument>
     <!-- Set the default document -->
      <files>
        <remove value="index.php" />
        <add value="index.php" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>

Comments

*_*

beautifulmind's picture

Is this equally applicable to normal Drupal package (not from Acquia)?

Thanks

:)
Beautifulmind

Yes. If you're running on

chicagomom's picture

Yes.

If you're running on IIS7, every site will have a web.config file in the site's root. The above file replicates the functionality of the .htaccess file provided in the Drupal 6 distribution.

chicagomom on Twitter and d.o.

oficial web.config

potss's picture

This Is oficial web.config
http://drupal.org/node/557898

paulvantuyl's picture

Hi when I have clean url's enabled, any path that ends or matches any of the url's listed in

<rule name="Protect files and directories from prying eyes" stopProcessing="true">
          <match url=".(engine|inc|info|install|module|profile|test|po|sh|.sql|postinst.1|theme|tpl(.php)?|xtmpl|svn-base)$|^(code-style.pl|Entries.|Repository|Root|Tag|Template|all-wcprops|entries|format)$" />
          <action type="CustomResponse" statusCode="403" subStatusCode="0" statusReason="Forbidden" statusDescription="Access is forbidden." />
        </rule>

they come back as a 403. For example, a blog posting of www.example.com/blog/author/test will match for |test| and give me a 403. Drupal 6.15, IIS 7, PHP 5, GoDaddy Shared Windows Hosting.

Just wanted to say I don't

paulvantuyl's picture

Just wanted to say I don't need a reply anymore. Client who was on IIS has now switched to Linux.

Sk8erPeter's picture

UPDATE!!!

Just realized (after inspecting the correct .htaccess file) that this web.config sample is FAULTY in some parts...
"Protect files and directories from prying eyes" rule isn't correct:
1. there's a missing backslash at the beginning - we have to escape the dot (".") character!! (These dot characters even disappear here on this forum of groups.drupal.org after posting!!! So we have to double these backslashes in our comment like \\!)
2. There is also a missing asterisk before "sql".
3. tpl(.php) isn't correct either, we have to escape dot character again - so the correct one is tpl(\.php)
4. code-style.pl is correctly code-style\.pl
5. Entries. has to be Entries.*
6. postinst.1 should MAYBE be postinst\.1 (what's this for??? That's the only one I'm not sure about...)

So the working rule is the following:

        <rule name="Protect files and directories from prying eyes" stopProcessing="true">
          <match url="\\.(engine|inc|info|install|module|profile|test|po|sh|.*sql|postinst\\.1|theme|tpl(\\.php)?|xtmpl|svn-base)$|^(code-style\\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$" />
          <action type="CustomResponse" statusCode="403" subStatusCode="0" statusReason="Forbidden" statusDescription="Access is forbidden." />
        </rule>

Here is my web.config for Drupal 6.



Previous comment (now outdated, except 3rd point):

Hi!

I can confirm @paulvantuyl's answer, this web.config setting can sometimes cause undesirable and undue 403 HTTP status codes.
We're using IIS 7.5 + URL Rewrite Module 2. I'm writing down my experiences below:

1.) The most confusing problem I saw related to this part of the web.config file is that it didn't let me flush the Drupal cache via Administration menu, because this rule matches "theme" string, and the link to flushing theme registry via Administration menu is something like this:
/admin_menu/flush-cache/theme?destination=user%2F1&token=cc95fef7a2fec234b3111920e5eb61d0
This address is blocked via the mentioned rule.
I wrote the details here too.

2.) This way I can't even reach e.g. Profile or Content Profile admin pages... Just to mention some addresses which give 403 error: /admin/user/profile, /admin/help/profile (help), /admin/content/node-type/profile/profile, /admin/advanced_help/content_profile (help).
These are unavailable because there's a match for the "profile" part. I get a 403 error... again. So cutting out the "profile" part from this rule solves the problem.


== related to "Force simple error message for requests for non-existent favicon.ico"
3.) Forcing 404 for the favicon.ico file causes that it's blocked everywhere!
For example, I have my own favicon.ico set in /sites/default/files/favicon.ico (but I do have the same one in root too, WHY NOT?! - in the previous Apache log I saw many 404 errors related to missing favicon.ico files in the root...), but Administration menu can't display it because of the rule...
I think forcing 404 for favicon.ico files in root directory doesn't make sense at all. If it really doesn't exist in the root (this is the fact with a default Drupal installation!), IIS (and Apache) will generate a 404 status code ANYWAY...
Our own favicon.ico file can be set (on e.g. /admin/build/themes/settings/global), and it's placed into /sites/default/files/favicon.ico by default... but why would it be a good idea to force an error message when it's needless (and generated by default)?

Maybe later I will discover more problems with it, these are the ones I had trouble with.

Please let me know if you have any opinions about the mentioned problems.

forbidden 403

alejuu's picture

Hi I´m having the #403 error when I'm trying to manage my database I'm runing Acquia in a Mac . I have to create a .htaccess file?? like the one that you put, and where did I have to create??? . I'm really amateur in this thinks and i´m going crazy with this problem thanks

Running IIS on a Mac?

markjbrown's picture

I'm confused :)

Error in you web.config

keyano's picture

We were having trouble with url ending in /test returning 403 on IIS
We looked at the .htaccess and web.config. In Web.config . were not escaped properly
<match url="\ .(engine|inc|info|install|module|profile|test|po|sh|.sql|postinst.1|theme|tpl(\ .php)?|xtmpl|svn-base)$|^(code-style\ .pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$" />

so instead of catching .test IIS was matching (ANY CHAR)test...

errorMode="Custom"

juahoo's picture

I had to add the errorMode="Custom" attribute to my web.config under httpErrors to get it to work correctly. Any idea why that would be?

<httpErrors errorMode="Custom">
  <remove statusCode="403" subStatusCode="-1" />
   <error statusCode="403" prefixLanguageFilePath="" path="/error/403.htm" responseMode="ExecuteURL" />
<remove statusCode="404" subStatusCode="-1" />
   <error statusCode="404" prefixLanguageFilePath="" path="/index.php" responseMode="ExecuteURL" />
<remove statusCode="500" subStatusCode="-1" />
   <error statusCode="500" prefixLanguageFilePath="" path="/error/500.htm" responseMode="ExecuteURL" />
</httpErrors>

Hello everyone I create a

DrupalEasy.ir's picture

Hello everyone
I create a website(D6) on linux/Apache and want to move it to Windows/IIS6
I have several problem :(. please help me !
I know I should translate htaccess to web.config , But I can't do this!
my old website is on here and new place here .
the clean url not working and my links not clean :(
the main problem , My images that customize with ImageCach module not shown :(

sorry, My English Language not well :(

please help me soon as possible.

Learn Drupal in Persian language ...
DrupalEasy.ir

Hi Amir, For clean URLs you

chicagomom's picture

Hi Amir,

For clean URLs you need an ISAPI Rewrite Filter. See this group's wiki for a couple of options for IIS6.

ImageCache relies on Clean URLs so get that going first and then see if you're still having difficulty with ImageCache.

Here is a post on working with ImageCache on IIS that you may find helpful as well.

chicagomom on Twitter and d.o.

Drupal install in windows server

mayur.pimple's picture

Site is working now. but links are not working. when click on any link then display blank page.

File Upload Size Limits for shared hostings

Geemi's picture

Hello,

I am designing a website using drupal 6.x. I am using the same web.config file for my website which is working fine in case of clean URLs. Now I want to increase the file upload limit; I don't actually now how to add that limit here in this web.config file. Can you please guide me abou tthat?

Thanks

Hello !I'm not sure it will

piercou's picture

Hello !

I'm not sure it will work on a shared box because the limitations can be hard-coded by your hoster, but you usually extend the file upload max size in the httpruntime section :

in system.web section, add
<httpRuntime maxRequestLength="4096" />
...

This defines a 4Meg limitation.

Pierre

Hello

gajanannehul's picture

Hello
Please tell me, i have to download .m4v video file which is 2GB.
what do i write in my web-config file to download this file. Currently it download is 276mb only.

Hi, what version of iis are

alexpilotti's picture

Hi, what version of iis are you using?

Hi alexpilotti , Im using 7.5

gajanannehul's picture

hi;
Im using 7.5 IIS version.Please help me.

7.5 IIS

Hi MicKraft,

gajanannehul's picture

Your link is not working

I'd start by adding the

alexpilotti's picture

I'd start by adding the proper mime type in the web.config (you can do it at the server level if you prefer):

<configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".m4v" mimeType="video/m4v" />
     </staticContent>
    </system.webServer>
</configuration>

Do you serve your m4v file as a static file or dynamically as response content of a PHP / ASP.Net page?

Alessandro Pilotti
MVP ASP.Net / IIS

Hi alexpilotti,

gajanannehul's picture

I did that, but now the problem is that, its download upto 276 mb and then stop.

IIS enforces upload limits,

alexpilotti's picture

IIS enforces upload limits, but not download limits (until 4GB).

To troubleshoot your problem I will start with a few questions:

  • Any related error on the server's event viewer?
  • Do you have the Output Caching enabled on your web site?
  • Are you testing the download through a proxy?
  • By trying to download the file via web browser on the server itself, the result is the same?
  • The download stops always at the same size? Can you post the exact value in bytes (non megabytes)?
  • Do you have an antivirus on the server? Can you exclude (during the test) your web site content from the scan?
  • The result is consistent with different web browsers?

Hi alexpilotti

gajanannehul's picture

Is their any module or do i add something to web-config file to increase download limit

HI

gajanannehul's picture

This is the error i got while downloading

D:\Gajanan\websites\moviedrome\ShutUp.m4v could not be saved, because the source file could not be read.

Try again later, or contact the server administrator.

Ok, can you please check the

alexpilotti's picture

Ok, can you please check the error on the server's event viewer? In case I need the full error data (eventId, etc).
Did you run through the checklist in my previous post?

hi

gajanannehul's picture

1)Any related error on the server's event viewer?
=> NO

2)Do you have the Output Caching enabled on your web site?
=> No

3)By trying to download the file via web browser on the server itself, the result is the same?
=> yes result is same that is,source file could not read.

4)The download stops always at the same size? Can you post the exact value in bytes (non megabytes)?
=>NO not stop at same size.

5) The result is consistent with different web browsers?
=>ya same on all browser

Hi alexpilotti

gajanannehul's picture

My problem is solved. Thanks, i think its because of firewall.

Hi alexpilotti

gajanannehul's picture

Need your help ....
i am using lm paypal module and i have to give back link to
my website on paypal subscripbtion page...

Don't ask it here

Sk8erPeter's picture

It's not related to IIS and web.config at all. So please don't ask it here. And DON'T duplicate your questions in the same topic...

Hi MicKraft;

gajanannehul's picture

Your link is not working.

It works for me. What is your

MicKraft's picture

It works for me. What is your e-Mail adress and I send it to you directly.

Hi MicKraft

gajanannehul's picture

Hi i am really sorry for my previous post...
Please tell me how do i prevent my video link from unauthenticated users.
Now i prevent that using session handling but the case is that IDM manager shows all
url path and if user copy and pest that url in other browser, video start download
and i am unable to manage that using session handling. somebody told me i can
manage that using web-config file by adding rule or something. If it possible please
tell me...

URL Rewrite

alexpilotti's picture

Hi,

you can perform some URL rewriting in IIS to hide the final URL from the user.
You can use WebPI to download the "URL rewrite" module.
Here's a starting point to learn the basics.

IMHO if possible, doing some PHP forwarding might provide a better approach in order to preserve the session context.

Best,

Alessandro Pilotti
MVP ASP.Net / IIS

I have been struggling with

Brian Edward's picture

I have been struggling with trying to get the URL redirect to work in web.config

Could someone please advise me on the correct way to write this.
Basically we have a directory full of pdf files that are now in a different directory since we switched to Drupal.
This wouldn't be an issue except many of the pdfs have embedded links that point to the full path of the old directory.

So i thought i could redirect the users.
the old directory is foia_files

before they would go to a URL like this.

www.example.com/foia_files/WP-01-001.pdf
now that same document lives in this folder
www.example.com/sites/default/files/document-library-files/2013/WP-01-00...

I tried this, but notice nothing.

<rule name="Rewrite FOIA_FILES to DOCUMENT_LIBRARY" stopProcessing="true">
                    <match url="^foia_files/([_0-9a-z-])" />
                    <action type="Redirect" url="/sites/default/files/document-library-files/2013/{R:1}" />
                </rule>

Any help would be appreciated.

Brian,Try this,

bwl7sju's picture

Brian,
Try this,

<rule name="Rewrite FOIA_FILES to DOCUMENT_LIBRARY" stopProcessing="true">
<match url="^foia_files/([_0-9a-z-]+)" />
<action type="Redirect" url="/sites/default/files/document-library-files/2013/{R:1}" />
</rule>

still did not work

Brian Edward's picture

bwl7sju-

I tried adding the + after the bracket. (that's the only different i noticed in your suggestion, correct?)
saved web.config
restarted web server.

tried to go to www.example.com/foia_files/wp-01-001.pdf
drupal did not redirect to anything.
instead went to page cannot be found and kept original url that i typed.

another modification

bwl7sju's picture

I forgot the .pdf in the match url.
try make it one of your first rules in your web.config file. It is working on my machine.

<rule name="Rewrite FOIA_FILES to DOCUMENT_LIBRARY" stopProcessing="true">
<match url="^foia_files/([_0-9a-z-]+.pdf)" />
<action type="Redirect" url="/sites/default/files/document-library-files/2013/{R:1}" />
</rule>

ok i'm almost there. i

Brian Edward's picture

ok i'm almost there. i restarted the entire server and now i get it to redirect EXCEPT it's not including the .pdf at the end of the path.

so it still goes to a page cannot be found.

how would i append the file extension to that redirect? they all are .pdf

thank you!

Saw something about IIS redirects

jeoware's picture

I was thinking of redirects a while back but found another way around it. Google had this: http://technet.microsoft.com/en-us/library/cc732969%28v=ws.10%29.aspx
Google: IIS redirects.

Jim

Thanks for all the help. That

Brian Edward's picture

Thanks for all the help.

That extra +.pdf was the trick.

Default web.config file for IIS 7.5 & Drupal 8

npcoder's picture

Hi,
I copy paste the code provided by @chicagomom. I could see error "The website encountered an unexpected error.Please try again later"

Also I amend her code according to @Sk8erPeter but get same error.

Could somebody provide workable web.config file for Druapl 8 in ISS 7.5?

Thanks.