I seriously doubt if anyone here can help with this, but I just can't get clean URLs working on my Drupal install.

I'm running my own LAMP server (Ubuntu Linux, Apache2, MySQL, PHP) and I think I've done what I'm supposed to do to get mod_rewrite running on my Apache server (according to my post on the Ubuntu Forums here: http://www.ubuntuforums.org/showthread.php?t=144782), but every time I put the default .htaccess into my Drupal directory, my website goes down.

So I tried a modified version of the .htaccess file, with only the IFModule/RewriteEngine On portion of it uncommented, and the Drupal admin/settings/clean URL just returned a:

"It appears your host is not configured correctly for Clean URLs. Please check for ModRewrite support with your administrator."

Does anyone here have an idea of what I'm doing wrong, or settings that need to be changed for me to use clean URLs?

Vince

Comments

sepeck’s picture

What directory is your Drupal installed in? If it's in a sub directory you may need to edit htaccess to account for that sub dir path

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

geme4472’s picture

...but if your domain hasn't propogated, you can't use clean URLs. (if this is blatantly obvious, I apologize)

pulsifer’s picture

Your ISP might have mod_rewrite disabled. There are a few ways to find out:

1. ask them

2. put this code in a file called phpinfo.php, upload it to your root directory, then navigate to www.yoursite.com/phpinfo.php:

<?php phpinfo(); ?>

Look in the apache section of the output, in "Loaded Modules", and see if you can find mod_rewrite.

3. Add these two lines to the top of the .htaccess in your root directory:

RewriteEngine on
RewriteRule .* http://drupal\.org [L,R]

If mod_rewrite is working, then whenever you go to your website you should be redirected to drupal.org

pulsifer’s picture

If its your own server, you can take the IFModule out of the .htaccess because you know it will be there.

You can also add these two lines to your .htaccess:

RewriteLog some-valid-path-to-a-log-file
RewriteLogLevel some-number-between-0-and-9--try-3-to-start

Then check your apache server logs as well as the rewrite log file you specified.

Note that most ISP's don't allow you to turn RewriteLog on because it can bog the server.

pulsifer’s picture

Definitely take out the "IfModule mod_rewrite.c". Then if mod_rewrite isn't loaded, the "RewriteEngine on" will cause an error msg in your server log.

jo1ene’s picture

I had to do this myself.

Advanced Web Design

VinceDee’s picture

sepeck, it's in the root directory, so I left the subdirectory part commented out

geme4472, the domain's been around for several weeks now, so I'm pretty sure it's as propagated as it's gonna get. Thanks for the suggestion, though.

pulsifer, I'm running my own server so I'm not sure why I'd need my ISP to have mod_rewrite enabled. That's an interesting suggestion about the redirecting, though, I'll try that out when traffic slows enough on my site sometime today (in case it causes it to go down).

Here's my link, in case it would do you any good:
http://www.ubuntuwebservers.com

Vince

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

bugz_nz’s picture

Hey Vince,

I had a similar problem - couldn't activate url rewrite even thought I knew it was configured correctly on the server.

I eventually edited my .htaccess file to say:

RewriteBase /

This is under the various rewrite rules section.

This got me working straight away.

satanas’s picture

Did you guys check whether the directive AllowOverride is set to "All".

e.g

<Directory "/path_of_your_site">

   AllowOverride All

</Directory>

This is Just a suggestion.. :)

S.

VinceDee’s picture

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

therave’s picture

Yeah - I built my own Linux development server recently (using Centos), and found, to my surprise, that the default httpd.conf had 'AllowOverride None' as the setting for all sites.

Strongly recommend you check for that as no rewrites will work when that is the case.


David Hamilton
http://www.jiffle.net/


David Hamilton
http://www.jiffle.net/

VinceDee’s picture

But it didn't work for me...same result...site was not accessible

Vince

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

meba’s picture

please paste your .htaccess, especially last 10 lines

VinceDee’s picture

It's 100% default. With my Drupal installation in the root directory, there isn't anything I should have to change, is there?

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.

Order deny,allow
Deny from all

# 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.

php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0

php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0

# Reduce the time dynamically generated pages are cache-able.

ExpiresByType text/html A1

# 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 /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 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 $

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

therave’s picture

I recently found a case where rewriting didn't work when hosted by 1and1. The solution turned out to be to prefix all of the rewrite destinations with '/'.

E.g.

  #RewriteRule node.php /index.php?q=node/view/%1 [L]

...

  #RewriteRule module.php /index.php?q=%1 [L]

... and

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

The rewrites were generating errors if rewrites were enabled, until this change was applied. Your mileage may vary, or course.

Regards
/david


David Hamilton
http://www.jiffle.net/


David Hamilton
http://www.jiffle.net/

aserdaten’s picture

David's suggestion cleared up a problem that's been driving me bats for three days. I moved a dev site to Network Solutions from Dreamhost, and there are so many oddities about Network Solutions hosting that I couldn't figure out which one was responsible.

For future Network Solutions customers looking for the answer to this question, remove this line from .htaccess at about line 42:

<IfModule mod_rewrite.c>

Because "Network Solutions doesn't run rewrite as a module", though it is in some ineffable zen way present nonetheless, so just remove the 'If' condition and it works.

Also, do what David says and add '/' before all rewrite destinations

Those two changes cleared up my Network Solutions problems.

Don't bother asking Network Solutions tech support for help because they don't know. They are very polite in telling you they don't know and don't waste your time pretending they do, which puts them in the top 5% of tech support in my book, regardless of being utterly useless in this unique circumstance.

bardsworth’s picture

So have this fun Network Solutions problem as well. I have drupal in a subdirectory called test. can you please look at this .htaccess file and tell me where i'm going wrong?

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
  Order allow,deny
</FilesMatch>

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
Options +FollowSymLinks

# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php

# Force simple error message for requests for non-existent favicon.ico.
<Files favicon.ico>
  # There is no end quote below, for compatibility with Apache 1.3.
  ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>

# 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
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   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
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   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
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

# Various rewrite rules.

  RewriteEngine on

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
  # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment and adapt the following:
  # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  RewriteBase /test
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

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

# $Id: .htaccess,v 1.90.2.4 2009/12/07 12:00:40 goba Exp $

I really need some help with this thanks so much!

JBstrikesagain’s picture

therave, I have been struggling to get this working all day (on and off). This suggestion fixed it for me. Thank you so much! Here is what I'm using now:

<VirtualHost *:80>
    ServerAdmin john@laptop.dj.edm
    DocumentRoot /usr/share/drupal
    ServerName laptop.dj.edm
    ErrorLog logs/laptop.dj.edm-error_log
    CustomLog logs/laptop.dj.edm-access_log common
  RewriteEngine on
RewriteCond  %{REQUEST_FILENAME} !^/$
  RewriteCond  %{REQUEST_FILENAME} !^/(files|misc|uploads)(/.*)?
  RewriteCond  %{REQUEST_FILENAME} !\.(php|ico|png|jpg|gif|css|js|html?)(\W.*)?
  RewriteRule ^/(.*)$ /index.php?q=$1 [L,QSA]
  RewriteLog /var/log/httpd/laptop.dj.edm-rewrite.log
  RewriteLogLevel 5
</VirtualHost>
pulsifer’s picture

Did you try #3 in http://drupal.org/node/54231#comment-102501? What happened?

VinceDee’s picture

I made a blank .htaccess file and put that string by itself in it:

RewriteEngine on
RewriteRule .* http://drupal\.org [L,R]

I refreshed my website and it sent me to drupal.org!

so, doesn't that mean that my mod_rewrite is working? If so, then what could be the problem?

Vince

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

VinceDee’s picture

I just narrowed down who the culprit is. It's these 2 guys:

Options -Indexes
Options +FollowSymLinks

I started with a default htaccess file and deleted all the comments, so I could see a simplified version. Then began by trying to run the file as is. Naturally, it was a nogo and my site was not accessible.

I next commented out the first two lines and ran the file: still a nogo

when I commented out the next two lines (those two above), my site stayed up. So, I left those commented and uncommented the first two lines. Then I got a "Forbidden: access denied" message, but that's a lot more promising than the previous "500 server error, and a host of other problems" message.

Either by itself or both of those two lines has the same effect of not working.

Does this help to make it any clearer to anyone what the problem might be?

Vince

and here's my latest slimmed-down htaccess file:

Order deny,allow
Deny from all

#Options -Indexes
#Options +FollowSymLinks

ErrorDocument 404 /index.php

DirectoryIndex index.php

php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0

ExpiresByType text/html A1

RewriteEngine on

RewriteBase /

#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 $

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

pulsifer’s picture

So the problem is a 500 server error when using Drupal's .htaccess? What does the server error log say?

VinceDee’s picture

[Wed Mar 15 15:44:29 2006] [alert] [client 24.7.108.240] /var/www/web6/web/.htaccess: Options not allowed here, referer: http://www.ubuntuwebservers.com/
[Wed Mar 15 15:44:29 2006] [alert] [client 24.7.108.240] /var/www/web6/web/.htaccess: Options not allowed here, referer: http://www.ubuntuwebservers.com/
[Wed Mar 15 15:45:28 2006] [error] [client 207.46.98.57] File does not exist: /var/www/web6/web/robots.txt

That last entry reminds me of what my next project has to be for this site: create a robots.txt file

Anyway, can you tell anything from those last three error.log entries? I'm too much of a newb to know what they mean.

Vince

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

pulsifer’s picture

If you remove the Options or comment them out (by prefixing them with a #), then everything works?

VinceDee’s picture

...if I comment out the two Options lines and the two first lines (with those in I get a "Forbidden: Access denied" message).

those error.log lines were from the server's /var/logs/ directory. Here's one from the website's directory:

[Wed Mar 15 16:11:24 2006] [alert] [client 24.7.108.240] /var/www/web6/web/.htaccess: Options not allowed here, referer: http://www.ubuntuwebservers.com/?q=toboggan/register

seems to be essentially the same, but it refers to the toboggan login.

Vince

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

pulsifer’s picture

You commented out all this:

Order deny,allow
Deny from all
Options -Indexes
Options +FollowSymLinks

and you're still getting an "Options not allowed"?

Are you sure that's not an old msg? Try clearing the log, or refresh the page and watch the time stamps closely to make sure you're still getting that error. Also, what url are you going to? What is your browser give you? A page of text that says what? A pop-up error msg that says what?

VinceDee’s picture

was with those 4 lines enabled (not commented out). When I comment out the Options lines and leave the other 2 enabled, I get a "Forbidden Access" message. when I comment out all 4 lines then everything appears to work properly.

Here's a jpg of the message that pops up in the browers:

http://www.ubuntuwebservers.com/500servererror.jpg

Vince

btw, I know it's got to be frustrating to you but I appreciate you helping me...it's above and beyond the call.

Vince

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

pulsifer’s picture

The problem with the first two lines is that you may not have the stock .htaccess file. Look at the actual file here: http://cvs.drupal.org/viewcvs/drupal/drupal/.htaccess?view=markup

Notice the FilesMatch lines before and after Order...Deny. Does your .htaccess have those? They are critical. (I've seen these lines missing before because things enclosed in lt gt signs like to get lost when viewed on web pages.)

The problem with the Options lines is that your server is not recognizing the "AllowOverride All". Maybe its not in the right place, maybe it has a typo, maybe the name of the vserver its applied to has a typo, etc. I don't know, but something like that is most likely the problem.

pulsifer’s picture

P.S. Another possibility is conflicting AllowOverride statements. Look for an AllowOverride None. In theory though you should be able to have an AllowOverride None at the head of your conf, and then override it with AllowOverride xxxx in specific vhosts, in specific directories, etc.

VinceDee’s picture

I have another website that I'm just starting to develop, based on Wordpress. Same server, same basic setup as the Drupal site that I'm having so much trouble with:

http://www.gadgetbugs.com

To see if mod_rewrite worked for that site, I enabled their simple URLs on it. After creating the .htaccess file manually (they don't provide you with one) and inserting the text that they provide, it worked...perfectly.

So, apparently mod_rewrite is enabled on the server, and works with at least one of my websites.

I've also looked at all the configuration files there are for apache2 and changed practically any AllowOverride that I found to All.

I'm getting the same result every time when I enable the htaccess file: my site gives a 500 server error.

I'm out of answers. Especially since mod_rewrite works with Wordpress.

Vince

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

pulsifer’s picture

From my understanding of what you have said, mod_rewrite and clean url's are working fine, as long as you comment out those offending four lines.

The four lines causing problems have nothing to do with mod_rewrite. They restrict access to certain files on the server for security purposes. Whether you have mod_rewrite or not, it is still a good idea to get those four lines working.

VinceDee’s picture

I just tried commenting out all four lines and running it. My site is accessible that way, but no clean URLs, which of course defeats the purpose of the whole exercise.

I'll keep messing around with it and let you know if I figure it out.

Thanks for the help,

Vince

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

pulsifer’s picture

Is "/var/www/web6/web/.htaccess" the .htaccess in your page root, or is it in a subdir? Are you sure that's the file you are looking at, the one in which you commented out the "Options"?

VinceDee’s picture

It's definitely the same .htaccess file. I'm using ISPConfig so my system has /var/www/web6/web/ as the subdirectory and page root directory for this website.

I just went over to the server and checked just to make absolutely sure, but it's the same directory. I should have explained that probably.

Vince

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

pulsifer’s picture

You probably need to add

AllowOverride All

to your apache .conf file. See http://httpd.apache.org/docs/1.3/mod/core.html#allowoverride

VinceDee’s picture

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

pulsifer’s picture

Yes, it looks like mod_rewrite is working. I suggest reinstalling the Drupal .htaccess (without the IFModule statements), then add the logging options I mentioned in http://drupal.org/node/54231#comment-102504. Add them right after "RewriteEngine on". If you turn the RewriteLogLevel up high enough (it goes to 9), somewhere in your logs (either the server logs or the Rewrite log) will be some clues about what is going wrong.

VinceDee’s picture

You can see my extremely long-winded solution to these various problems here:

http://drupal.org/node/54425

Vince

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com

---------
The hottest Linux distribution? Ubuntu
Talk about Ubuntu Web Servers at:
http://www.ubuntuwebservers.com