Any tips on getting clean URLs to work under Apache2? I can get the home page to come up just fine (e.g. http://myhost/drupal).

But when I try to follow a link that is a drupal path (say something like http://myhost/drupal/taxonomy/term/2), I get a "Bad Request. Your browser sent a request that this server could not understand." error.

If I manually rewrite the URL to "http://myhost/drupal/index.php?q=taxonomy/term/2" it works fine.

I've got mod_rewrite logging turned way up, and it looks to me like the right rewriting is happening... in the log it eventually gets to:

192.168.1.1 - - [13/Dec/2004:21:22:12 --0500] [myhost/sid#23c4b0][rid#2289f38/initial] (2) [per-dir D:/drupal/] rewrite taxonomy/term/2 -> index.php?q=taxonomy/term/2
192.168.1.1 - - [13/Dec/2004:21:22:12 --0500] [myhost/sid#23c4b0][rid#2289f38/initial] (3) split uri=index.php?q=taxonomy/term/2 -> uri=index.php, args=q=taxonomy/term/2

but then it does, which may or may not be a problem:

192.168.1.1 - - [13/Dec/2004:21:22:12 --0500] [myhost/sid#23c4b0][rid#2289f38/initial] (3) [per-dir D:/drupal/] add per-dir prefix: index.php -> D:/drupal/index.php
192.168.1.1 - - [13/Dec/2004:21:22:12 --0500] [myhost/sid#23c4b0][rid#2289f38/initial] (1) [per-dir D:/drupal/] internal redirect with D:/drupal/index.php [INTERNAL REDIRECT]

(all those paths are correct, btw).

When I give the non-clean URL manually, I don't get those last 2 lines in the rewrite log.

Any thoughts? Thanks - dwh

Comments

Alaska’s picture

Not sure if this is part of the answer or not. But could not use clean URLs and asked the web host what the issue could be. This is what they said.

Within your .htaccess file all you need to do is add

Options All
RewriteEngine on

and that will turn on the mod_rewrite engine for you.

Added Options All to the file and clean URLs now works. Let me know if this did or did not work....

Jim

denishaskin’s picture

Are you implying I should try RewriteEngine On but not have any of the rewrite rules and conditions?

Alaska’s picture

The only change that was made to the htaccess file was to add, in my case, "Options All". Everything else was left as is - i.e. no changes to the rewrite rules, etc. Here is part of the code with the last line being added to htaccess.

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

This may not be the issue in your case, but it made my clean URLs go form non functional to working.

Also in htaccess the following statement is made in regard to which flavor of Apache is being used.

# Overload PHP variables:
<IfModule mod_php4.c>
   # If you are using Apache 2, you have to use <IfModule sapi_apache2.c>
   # instead of <IfModule mod_php4.c>.
denishaskin’s picture

Whew, finally resolved it. Looks like it was because I had my RewriteBase wrong (although I could have sworn I had tried this before without success).

The commentabout RewriteBase in drupal's .htaccess is a little unclear: "if you are using Drupal in a subdirectory". What this apparently means is whether drupal is your DocumentRoot or not. In my case it wasn't (e.g. I wanted to access the drupal site with something like http://mynode.com/drupal instead of just http://mynode).

So all I did was set RewriteBase to /mynode and it worked. I think it may have taken me a while to get here because I was changing too many things in httpd.conf and .htaccess at the same time... shame on me.

Okay, now that clean URLs are working, back to working on the site content itself...