Drupal and Apache Rewrite Rules

Discussion in 'Server Operation' started by andre, Apr 25, 2005.

  1. andre

    andre New Member

    Hi,

    I've set up a Drupal-based web site. Drupal is right in the web server's document root. Now Drupal can generate search-engine friendly URLs (www.domain.com/a/b/c instead of www.domain.com/index.php?1=a&2=b&3=c), but to use this feature I have to create a .htaccess file with Apache rewrite rules in the document root.
    Drupal comes with a sample .htaccess file, but it's not working. The rewrite rules look like this:

    Code:
    # 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 /drupal
    
      # 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 URLs of the form 'index.php?q=x':
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    </IfModule>
    What's wrong here?

    Andre
     
  2. falko

    falko Super Moderator ISPConfig Developer

    Try this:

    Code:
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
    </IfModule>
    (Note the / in front of index.php!)
     
  3. uli

    uli New Member

    I have the same problem, but my Drupal is not in the document root, but in the subdirectory drupal. Does it make a difference (because falko's solution doesn't work for me...)?

    Uli
     
  4. falko

    falko Super Moderator ISPConfig Developer

    Code:
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteBase /drupal/
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    </IfModule>
    might work.
     
  5. timbo

    timbo New Member

    Clean URLs for Drupal??

    Hi,

    I am also trying desperately to enable Clean URLs for my drupal installation.

    I have a fresh installation of ISPConfig 2.1.1 and have my drupal installation in /var/www/web1 (www.10thdimens10n.com).

    I have tried editing the .htaccess file according to above, however this only results in a 500 internal server error.

    The drupal documentation for clean urls is here. http://drupal.org/node/15365 Could someone perhaps have a look?

    in addition:

    the output of /var/www/web1/.htaccess:
    Code:
    #
    # Apache/PHP/Drupal settings:
    #
    
    # Protect files and directories from prying eyes.
    <Files ~ "(\.(inc|module|pl|sh|sql|theme|engine|xtmpl)|Entries|Repositories|Root|scripts|updates)$">
      Order deny,allow
      Deny from all
    </Files>
    
    # 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 exist in sites/default/settings.php, but
    # the following cannot be changed at runtime. The first IfModule is
    # for Apache 1.3, the second for Apache 2.
    <IfModule mod_php4.c>
      php_value magic_quotes_gpc                0
      php_value register_globals                0
      php_value session.auto_start              0
    </IfModule>
    
    <IfModule sapi_apache2.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 /var/www/web1
    
      # 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>
    
     
    Last edited: Nov 19, 2005
  6. timbo

    timbo New Member

    My apache2.conf file is too long to post here. let me know if and what part you might need to look at if any.

    Thanks a truckload in advance. You guys rock.
     
  7. falko

    falko Super Moderator ISPConfig Developer

    You are in the wrong folder. The correct folder to install Drupal is /var/www/web1/web.
     
  8. timbo

    timbo New Member

    Okay. Now I'm totally confused. Why is everything which is installed into the /var/www/web1/web folder mirrored into /var/www/web1?

    When I move the file .htaccess from /var/www/web1 into /var/www/web1/web and point to my site, the server returns a 500 internal error. When I take it out out, the site works. What gives?

    What is in that drupal .htaccess file that disagrees with my LAMP setup? :confused:
     
  9. timbo

    timbo New Member

    Got it!

    I see now. I CREATED the .htaccess file using the code here:

    I thought you were telling him to add that to his existing .htaccess file.
    My clean urls are working! Thanks!

    tb
     
  10. stamy

    stamy New Member

    Hello, i have a big trouble to install drupal 4.7 (the latest one) on ISPConfig 2.2.1 on a Debian Sarge.

    I get an 500 internal error when i put this f****** .htacces file in my root directory: /var/www/web1/web/.htacces

    I have modified the .htacces file (putting a slash before index.php ...like Falko's previous post)
    I have installed drupal directly under /var/www/web1/web (no sub-directoy).

    Here is my log file: (under web1/log/error.log)

    [Thu May 04 20:03:59 2006] [alert] [client 82.231.213.145] /var/www/web1/web/.htaccess: Options not allowed here
    [Thu May 04 20:03:59 2006] [alert] [client 82.231.213.145] /var/www/web1/web/.htaccess: Options not allowed here
    [Thu May 04 20:04:00 2006] [alert] [client 82.231.213.145] /var/www/web1/web/.htaccess: Options not allowed here
    [Thu May 04 20:04:00 2006] [alert] [client 82.231.213.145] /var/www/web1/web/.htaccess: Options not allowed here
    [Thu May 04 20:04:58 2006] [alert] [client 82.231.213.145] /var/www/web1/web/.htaccess: Options not allowed here
    [Thu May 04 20:04:58 2006] [alert] [client 82.231.213.145] /var/www/web1/web/.htaccess: Options not allowed here
    [Thu May 04 20:04:58 2006] [alert] [client 82.231.213.145] /var/www/web1/web/.htaccess: Options not allowed here
    [Thu May 04 20:04:58 2006] [alert] [client 82.231.213.145] /var/www/web1/web/.htaccess: Options not allowed here
    [Thu May 04 20:04:59 2006] [alert] [client 82.231.213.145] /var/www/web1/web/.htaccess: Options not allowed here
    [Thu May 04 20:04:59 2006] [alert] [client 82.231.213.145] /var/www/web1/web/.htaccess: Options not allowed here

    Thank's for your help !
    I guess these is a option like AllowOverride All but i dont known where to put it (maybe in /etc/apache2... ?)
     
  11. stamy

    stamy New Member

Share This Page