Mod_rewrite unrecognized as enabled

Silverstripe Version: 4.1

Question:

Hello,
I was in the install process and I had to disable the following directive on .htaccess because my server does not allow it. Yet the Rewrite engine is on but the requirement check process was stopping because of this.

    #SetEnv HTTP_MOD_REWRITE On

So I forced the return to “true” in the following function in
vendor/silverstripe/framework/src/Dev/Install/InstallRequirements.php

    public function testApacheRewriteExists($moduleName = 'mod_rewrite')
    {
        if (function_exists('apache_get_modules') && in_array($moduleName, apache_get_modules())) {
            return true;
        }
        if (isset($_SERVER['HTTP_MOD_REWRITE']) && $_SERVER['HTTP_MOD_REWRITE'] == 'On') {
            return true;
        }
        if (isset($_SERVER['REDIRECT_HTTP_MOD_REWRITE']) && $_SERVER['REDIRECT_HTTP_MOD_REWRITE'] == 'On') {
            return true;
        }
//        return false;
	  return true;
    }

Then obviously test passed. But the next install process had stop again

  • Setting up /home/user/public_html/test/public/index.php
  • Setting up /home/user/public_html/test/mysite/_config.php
  • Setting up /home/user/public_html/test/mysite/_config/theme.yml
  • Setting up /home/user/public_html/test/.env
  • Setting up /home/user/public_html/test/public/.htaccess
  • Building database schema…
  • Creating default CMS admin account…
  • Checking that friendly URLs work…
  • Friendly URLs are not working. This is most likely because a rewrite module isn’t configured correctly on your site. You may need to get your web host or server administrator to do this for you:
    • mod_rewrite or other rewrite module is enabled on your web server
    • AllowOverride All is set for the directory where SilverStripe is installed

indeed the mod_rewrite is ENABLED and I con fortunately confirm the site seems to be up and running
(I had to re-comment again the SetEnv directive in public/.htaccess

I found this thread on StackOverflow and the fix worked for me!
https://stackoverflow.com/questions/52373857/silverstripe-install-friendly-urls-not-working

Basically, you just change the permissions on /public/index.php from 755 to 644 (I changed permissions on /public/.htaccess as well).

Hope this works for you!

1 Like

Oh … you’ve solved it!!! Thank you so much :slight_smile:

1 Like

I can’t see the “Theme” dropdown menu into admin/settings/

I only see “Site title” and Site tagline /Slogan

I installed bootstrap theme using composer.

Hi Nicola, the theme picker has been removed in SS4 - please take a moment to look over the Changelog to see what else is different, as it is quite the step from 3 to 4.

I’ve created a module to restore the theme dropdown here if you want to re-enable that functionality.

Hi Nicola, did you get anywhere with this, in the end? I have the same issue and am not making any progress

I too am having the same mod_rewrite issue on installing 4.2.1 and can’t seem to resolve it. SS v3.x installs and runs correctly but v4.x dies at the Friendly URL step. Curiously, v4.x installs flawlessly on my local Windows/WAMP server. I’m stumped.

1 Like

I’ve emailed Cam Findlay at SilverStripe - if I get a reply I’ll update you all here :slight_smile:

1 Like

I haven’t heard from Cam yet, but I’ve started wondering if this issue is being caused by attempting to install SS in a subdirectory (rather than at the root). I did actually successfully install SS 4.x at the root of my hosting, as a test, whereas I wasn’t able to install it in any subdir due to the mod_rewrite issue.

I tried to solve the problem by modifying the installer file to set the base dir to the subdir but it was ignored during installation. I then tried to modify the .htaccess in the same way, but the installer overwrites it with the default settings. Do you happen to know where I can set the base dir properly? Maybe that will help. I just can’t believe we can ONLY install SS 4.x at the root from now on.

By the way, if you’re in a rush to install SS 4.x, one thing I found works is to install it at the root first, THEN create a subdir, move all the site files into that, update the .htaccess to set the base dir to the sub dir, and you’re good to go :slight_smile: Bit of a clumsy solution, but maybe worth doing until later versions of SS 4.x can cope with subdir installations.

You should be able to install SS4 in a subdirectory by not using the public directory at all (since the benefits aren’t really there in that situation):

  • Get into the web root
  • Create the project in the normal way: composer create-project silverstripe/installer ./mysubdir
  • Once the installer has finished, copy the contents of the public directory (including the .htaccess file) into the installation root (ie. one level up, where the vendor directory lives) - This will overwrite the existing .htaccess file
  • Delete the (now empty) public directory
  • Run composer vendor-expose
  • Point your browser at http://example.com/mysubdir and you should see the installer

You may need to set the SS_BASE_URL="http://example.com/mysubdir/" in your .env file if you get issues.

1 Like

Thanks, John. A poster in another thread suggested a similar thing: that the server web root should point to the /public directory. I’m not desperate to get it running, but I might try your install solution if I have time.

1 Like

Hi all, this is what Cam Findlay has advised:

Hi John,

I haven’t worked at SilverStripe (the company that is) in a couple of years. Here’s what I can suggest from a quick read of the thread.

Assuming you’re looking to run SilverStripe 4 on some shared hosting (as opposed to a dedicated virtual server or other) it’ll come down to how that host handles mod_rewrite and how much it will let you change things.

There is a .htaccess file in the root directory of a default SS4 install that deals with rewriting requests into the ‘public’ directory so you shouldn’t need to move any files about to try and trick it into working.

If your SS3 install works on the same hosting it might be to do with the ‘index.php’ file in the root directly that came with that version (which acts as a bit of a fall back if the proper mod_rewrites aren’t quite doing their thing). SS4 doesn’t have this it’s all done with the .htaccess file these days.

Your host might allow some mod_rewrite configuration tweaks via your .htaccess file (without knowing what host you are using hard to directly answer your question).

When I’ve hit similar issues in the past the likely culprit was an Apache settings called “AllowOverride” which needs to be set to “All” to allow your local .htaccess file to correctly kick in.

Rewrite can be ENABLED but wont behave correctly for SilverStripe if that setting isn’t correctly set… it’s mentioned in the docs at: Server Requirements – SilverStripe Documentation

" Apache 2.0+ with mod_rewrite and “AllowOverride All” set "

Suggest getting across learning more about Apache rewrites (they can be a pain until you get your head around what’s going on under the hood).

Sorry I can’t be of more help but hope that points you in the right direction.

C.