I recently found out that Clean URLs might simply not work on some web hosters, e.g. 1&1 Internet, although mod_rewrite is enabled on these systems. This is because these hosters might have some special ways of enabling mod_rewrite.

All seems set up correclty, your web hoster says that mod_rewrite is working and can be used, still Drupal complains that your web hoster does not allow the rewriting of URLs and that the system administrator should be contacted.

This is what happens:

In Drupal's .htaccess file you might find a statement just above the Rewrite rules. Now, some web hosters, especially 1&1 Internet, seems to "hide" the module although it is there (I am not an expert on large scale web hosting technology and setting up Apache Servers in typical large scale web hosting environments, so if anyone has an explanation, please let me know!)

So to make Clean URLs work in such an environment, simply delete the line or place a # in front of it to comment it out, look all the way down and find and delete that to (or palce an # in front of it). Also, especially for 1&1, it's vital to tell the server where the RewriteBase is, even if it is in the web root, so change "#RewriteBase /drupal" to "RewriteBase /" if your site's right in the web root or "RewriteBase /drupal" if it is in the subdirectory "drupal"...

And this makes your .htaccess file compatible to those web hosters as the .htaccess file simply is not checking if or if not a mod_rewrite.c can be found but runs the rewrite rules anyway!

Careful though to not use this when there really is NO rewrite module on the particular web server!

Hope this helps !

Greetings, Steve

Comments

alliax’s picture

It would have helped me just 2 weeks ago when I started my first drupal site with 1and1 !
Fortunately I found out another thread, I think it was on Drupal.org, and the solution was to edit one of the last lines of the .htaccess

instead of :
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

you add a / like this :
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]

But I suppose both solutions equals the same as I have had no troubles with clean_urls ever since. Please tell me if there is a difference as I will be monitoring this thread to see your answer.

Thank you for taking the time to create this well keyworded thread.

Cheers,

gateone’s picture

Hi,

yes, what you found basically is part of my discovery. So what's going on here...

instead of :
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

you add a / like this :
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]

...is that you simply tell the rewrite engine where the rewrite base is. If you say index.php you mean an index.php anywhere in any given subdirectory, if you say /index.php you definitively mean the index.php that sits in the web root.

On my approach, this has already be done by saying "RewriteBase / " -- so it is either your approach with the RewriteBase commented out or you leave the rule as it is and add "RewriteBase / " (assuming, that Drupal is in the web root and not in a subdirectory).

Here is my complete modified Rewrite ruleset:

# Various rewrite rules.

  RewriteEngine on

  # Modify the RewriteBase if you are using Drupal in a subdirectory and
  # the rewrite rules are not working properly.
  RewriteBase /

  # Rewrite old-style URLs of the form 'node.php?id=x'.
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{QUERY_STRING} ^id=([^&]+)$
  #RewriteRule node.php index.php?q=node/view/%1 [L]

  # Rewrite old-style URLs of the form 'module.php?mod=x'.
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
  #RewriteRule module.php index.php?q=%1 [L]

  # Rewrite current-style URLs of the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


# $Id: .htaccess,v 1.66 2005/03/20 19:15:00 dries Exp $

So you see the condition is left out as we KNOW for sure there is some sort of rewrite engine but it simply does not seam to listening on the name "mod_rewrite.c". Also, the RewriteBase is states as / (that is the web root). So you can leave the rest as it is. OR, comment out RewriteBase and add / to the index.php. Either works, but I would suggest using the "proper" way as in my example above with a defined RewriteBase of / just to keep things standardized! ;-)

Steve

alliax’s picture

Thank you for the clarification, it's clear now. Cheers,

mrlegend90’s picture

I have tried all of the above now I am completly locked out. I am also hosting on 1and1. my drupal files exist in the directory /compusulting. After my initial install I had an issue with my base url and could only get to my site by http:\\compusulting.net\compusulting. I changed the destination in the domains admin in the 1and1 cpanel to /compusulting and I could then reach my site now to get the clean url's up and going I have tried every variation that was mentioned above and I still get a 500 error. My last attempt at the .ht access file is below. If some with expirence with 1and1 could take a look at this it would be greatly appreciated. Thank-You website is http:\\compusulting.net

On line 56 you will notice RewriteBase /compusulting I had to do this to get my site to work at all because of my initial issue with base url, but I have tried all the variations I believe.

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "(\.(engine|inc|install|module|sh|.*sql|theme|tpl|xtmpl)|code-style\.pl|Entries.*|Repository|Root)$">
  Order deny,allow
  Deny from all
</FilesMatch>

# Set some options.
Options -Indexes
Options +FollowSymLinks

# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

# PHP 4, Apache 1
<IfModule mod_php4.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
</IfModule>

# PHP 4, Apache 2
<IfModule sapi_apache2.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
</IfModule>

# PHP 5, Apache 1 and 2
<IfModule mod_php5.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
</IfModule>

# Reduce the time dynamically generated pages are cache-able.
<IfModule mod_expires.c>
  ExpiresByType text/html A1
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  #RewriteEngine on

  # Modify the RewriteBase if you are using Drupal in a subdirectory and
  # the rewrite rules are not working properly.
  RewriteBase /compusulting

  # Rewrite old-style URLs of the form 'node.php?id=x'.
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{QUERY_STRING} ^id=([^&]+)$
  #RewriteRule node.php index.php?q=node/view/%1 [L]

  # Rewrite old-style URLs of the form 'module.php?mod=x'.
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
  #RewriteRule module.php index.php?q=%1 [L]

  # Rewrite current-style URLs of the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

# $Id: .htaccess,v 1.70 2006/03/24 18:00:27 killes Exp $
e61’s picture

Hello, I am a german 1und1 customer setting up drupal 4.7.0 right now. The above mentioned modification works for me. But I lost some time on this issue anyway (maybe this pretty obvious if you are deeper in apache et. al. but I am not):

My testsite is located on an additional 3rd-level-domain like coolsite.example.com.
coolsite.example.com is linked to a folder /drupal47 within my site.
In this case the (relative) basedir to use in .htaccess falls back to /

sakib000’s picture

If you install drupal in subdirectory, then you have to uncomment

# RewriteBase /

to

RewriteBase /subdir_name