In Drupal 8 mod_rewrite is no longer required. However I am experiencing problems with generating files through Image styles when mod_rewrite is not enabled. I have not been able to spot any warnings - hook_requirements() etc. - that this should be a problem.

When trying to access an url such as http://host/sites/default/files/styles/thumbnail/public/filename.jpg?ito... on a server without mod_rewrite results in a 404 with the following line written to the server log: File does not exist: /path/to/webroot/sites/default/files/styles/thumbnail/public/filename.jpg. As far as I can tell Apache does not go through PHP here.

Enabling mod_rewrite fixes the issue.

Environment info:
- Apache 2.4.10
- PHP 5.5.47-0+deb8u1
- Drupal 8.1.1

Comments

kasperg created an issue. See original summary.

kasperg’s picture

To be honest I do not know whether mod_rewrite is required or not.

https://www.drupal.org/requirements/webserver says yes but #2382513: Regression fix: allow Drupal 8 to work without Apache mod_rewrite indicates no.

tetranz’s picture

I was caught out by this.

I just setup a new development system (Ubuntu 16.04 LTS). Everything worked wonderfully except image styles. I finally found this issue realized that I had forgotten to enable mod_rewrite.

I haven't looked to see if it is fixable or not. If not, then I think there should be a documented warning somewhere.

tetranz’s picture

I took a look at this.

Image styles do not work without mod_rewrite because of the security related SetHandler lines in sites/default/files/.htaccess

i.e.,

# Set the catch-all handler to prevent scripts from being executed.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<Files *>
  # Override the handler again if we're run later in the evaluation list.
  SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
</Files>

With those in place, the FallbackResource directive in the root .htaccess does not work. A request to a non-existent /sites/default/files/someimage.png does not fall back to index.php. It returns a 404.

Images styles work without mod_rewrite if the SetHandler lines are removed or commented out.

I don't know if there is a secure solution to this. We probably need comments from some security experts.

Even though it's been long closed, I'll add https://www.drupal.org/node/2382513 as a related issue. The final result of that issue perhaps isn't as complete as was thought at the time.

tetranz’s picture

kattekrab’s picture

Yet another sting related to the behaviour change around Clean URLs for D8.

Documentation here: https://www.drupal.org/getting-started/clean-urls#enabling-8

Enabling Clean URLs in Drupal

The standard Drupal installation contains a sample .htaccess file that supports Clean URLs, so make sure this file exists before enabling Clean URLs. Before copying this file make sure there is a dot , in the .htaccess file's name. It is very important to how Apache works.

Drupal 8.x

In Drupal 8, clean URLS are enabled by default and can't be disabled. You will need some form of rewrite module installed on your web server.

Drupal 7.x

In Drupal 7, the installer tests for compatibility with Clean URLs as a part of the installation process. If the environment is tested as compatible with Clean URLs, it will be enabled as part of the installation process and no further action is required to enable Clean URLs.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

marysmech’s picture

I had experiencing same problem with images styles. Image crops were not generated and there was no error.

After little debugging I have found out that if I remove "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003" from "files" .htaccess everything work. Than I have found this thread and enabled apache's mod_rewrite and images style are now generated correctly.

Thank you!

zorlin’s picture

Chiming in to say that we were having issues with image generation etc due to the .htaccess file in sites/default/files - and had removed it as a temporary workaround on 2 different Drupal8 sites.

I was unhappy at the idea of degrading our security and so have been researching a proper fix - simply enabling mod_rewrite has fixed the issue and allowed us to put the .htaccess back into proper usage.

Thanks to @chi on Slack for pointing me to this page. Very glad to have this issue solved.

(So, yes, it probably /does/ require mod_rewrite still ;))

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

renrhaf’s picture

I encountered the same issue with Drupal 8.6.1 and using Apache without mod_rewrite enabled.
Everything seemed to work properly but the image styles.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

kristen pol’s picture

Version: 8.9.x-dev » 9.1.x-dev
Issue tags: +Bug Smash Initiative

This was a problem recently for simplytest.me. Adding mod_rewrite fixed the issue:

#3162126: Image styles either aren't generated or can't be downloaded

This is a big deal and it's not obvious what's wrong because there are no errors in the Drupal logs.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Status: Active » Fixed

The webserver requirements now say the following

You can use the Apache 'mod_rewrite' extension to allow for clean URLs. Note that with Drupal 8, clean urls are enabled by default and can't be disabled, so mod_rewrite needs to be installed and enabled for Drupal 8 to work.

So we can mark this as fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.