Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UX] Detect whether mod_rewrite is enabled (in Apache installs) and throw a warning in the clean URLs page. #1573

Open
klonos opened this issue Jan 23, 2016 · 9 comments

Comments

@klonos
Copy link
Member

klonos commented Jan 23, 2016

Here's the deal...

  • I see that clean URLs are not enabled,
  • I head over to ?q=admin/config/search/urls to run the test. Test says "no go".
  • I know that there's a known issue about this (https://www.drupal.org/node/1134934), so I just give it a go nevertheless by removing the ?q= part of the URL. ...404
  • I enable AllowOverride All etc. in my apache settings and restart the service.
  • I try the clean URL admin/config/search/urls and it works!!
  • Great, but then going back to the ?q=admin/config/search/urls page shows that "Clean URLs cannot be enabled." and running the test throws a "The clean URL test failed." message.
  • Fine, try the clean URL again admin/config/search/urls ...it works and gives me the option to enable clean URLs. WTF#1
  • Perhaps I need to click the "Enable clean URLs" checkbox to make it stick... so I tick, I hit save aaand... WTF#2: the checkbox is unchecked after the page is reloaded?!?

I repeat the tick and save a couple of times... still the checkbox comes as unchecked ...but the clean URLs work?!? ...well only if I manually type them in the address bar. If I visit the website still all menu links (in primary navigation for example) are using the non-clean form.

Something I'm doing wrong or bug?

@serundeputy
Copy link
Member

There can be quite a few reasons that this does not work. I've had a few of my own battles with this in drupal land in different environments.

  • Make sure you have Apache mod_rewrite module enabled, if you are using nginx there must be some equivalent.

@klonos
Copy link
Member Author

klonos commented Jan 24, 2016

Rookie mistake. Thanx @serundeputy

@klonos
Copy link
Member Author

klonos commented Jan 24, 2016

...can we have it so that we detect this and have a warning in the clean URLs page so to give pointers to forgetful people like myself?

@klonos klonos changed the title Problem with enabling clean URLs. [UX] Detect whether mod_rewrite is enabled (in Apache installs) and throw a warning in the clean URLs page. Jan 24, 2016
@klonos
Copy link
Member Author

klonos commented Jan 24, 2016

Perhaps also have an entry with class="info" in the site status page (same as we have for Upload progress).

@klonos
Copy link
Member Author

klonos commented Jan 24, 2016

...the messages could be along the lines of:

  • "mod_rewrite is not enabled. If you enable it (link to documentation), you will be able to use Clean URLs (link to ?q=admin/config/search/urls)."
  • "mod_rewrite is enabled. You can use Clean URLs (link to admin/config/search/urls) to improve your site's SEO."
  • "mod_rewrite and Clean URLs enabled."

@klonos
Copy link
Member Author

klonos commented Jan 27, 2016

I managed to put together this piece of code that works in detecting if mod_rewrite is present/enabled:

<?php
  $modules[] = apache_get_modules();
  foreach ($modules[0] as $module) {
    if ($module == 'mod_rewrite') {
      echo 'enabled';
    }
  }
?>

Hope it helps

@serundeputy
Copy link
Member

I've filed a PR at backdrop/backdrop#1230 , but there are some concerns.

There is not a very reliable way to tell what web server an environment is using; http://serverfault.com/questions/164130/how-to-detect-in-php-if-it-is-running-on-apache-nginx-or-some-other-webserver

There is no corresponding nginx_get_modules() function and apache_get_modules() apparently does not work for php as cgi users.

Not sure if this is insurmountable or it is a better message for >80% of users or what. @quicksketch you have ideas, opinions or concerns on these issues?

screen shot 2016-01-29 at 8 12 16 pm

@ghost
Copy link

ghost commented Sep 6, 2019

Ping @quicksketch

@indigoxela
Copy link
Member

This branch has conflicts that must be resolved. And there also seem to be some concerns regarding the approach (two messages with different types about the same thing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants