Failing to enable mod_rewrite on Ubuntu 10.10

I've done a lot of reading on these forums and elsewhere, but I can't seem to get mod_rewrite working on my Linode despite my efforts.

I have apache2 installed, have run 'a2enmod rewrite' and /etc/init.d/apache2 restart' multiple times, but I can't seem to get mod_rewrite to work.

I looked at my phpinfo page and mod_rewrite is listed as a loaded module.

However, when I try even the simplest Rewrite rules, they simply don't work.

Here is my .htaccess file located in /var/www/.htaccess

RewriteEngine on
RewriteRule ^2227/$ index.php?s=2227 [L]

When I visit /index.php?s=2227, my site loads fine, but visiting /2227 just brings me to a 404 page and my Apache error logs reflect this saying:

File does not exist: /var/www/2227

I have my chmod 775'd my .htaccess file.

Is there anything here that I'm missing or any reason at all why mod_rewrite wouldn't be working for me in this instance?

12 Replies

It looks like your rewrite rule matches http://domain.com/2227/ (with a trailing slash), but you're requesting http://domain.com/2227 (without a trailing slash).

I've tried both with and without the trailing slash with no luck. :(

you're doing this in .htaccess, are you allowing that with AllowOverride in your main configuration? (either All or FileInfo)

Maybe you need to add "AllowOverride All" to the appropriate block in your apache configuration file (either apache2.conf, httpd.conf, one of the files in a place like /etc/apache2/sites-available/, or somewhere else), and then reload apache.

I just tried adding the following to /etc/apache2/httpd.conf and restarting Apache with no luck:

 <directory var="" www="">AllowOverride All</directory> 

and (from http://mathiasbynens.be/notes/apache-allowoverride-all)

 <directory>Options FollowSymLinks
 AllowOverride AuthConfig FileInfo Indexes Limit Options=All,MultiViews
 Order deny,allow
 Deny from all</directory> 

Is there anything else I could be missing?

Has anybody managed to get mod_rewrite working on their Linode boxes?

@mikepink:

Has anybody managed to get mod_rewrite working on their Linode boxes?

Yes

What steps did you take to get it working?

Thought you might want more detail :)

I'm running Debian, but that's what Ubuntu is based off of.

sudo a2enmod rewrite

That's it. I run a couple sites that have several different versions of Gallery installed and they are all using url rewriting without an issue.

I wish it were that simple for me :)

If anyone has time, would you mind looking at my phpinfo and seeing if there's anything glaringly wrong with it that might prevent mod_rewrite from working?

http://173.230.158.141/info.php

So I ended up running a2dismod and a2enmod with no luck, but what eventually worked for me is this:

removing /var/www/.htaccess

putting my rewrite rules in /etc/apache2/httpd.conf

editing my virtual hosts file to turn on the RewriteEngine and setting RewriteOptions to Inherit

restarting apache

This works, but everytime I want to change a rewrite rule, I need to restart Apache. It's not ideal, but it gets the job done.

I had rewrites working on my Ubuntu 9.10 linode and upgraded to 10.10 and they still work ok.

Since you got rewrites working in httpd.conf it is sort of looking like the module is being loaded but your .htaccess files aren't being read. Can you try other directives in .htaccess and see if they work?

In /etc/apache2/apache2.conf I have

AccessFileName .htaccess

I'm assuming you have that - but it's worth checking.

Then in my /etc/apache2/sites-available/ I have all my vhosts files. Inside those are the directives for each vhost. Inside the sections in those files I have "AllowOverride All" for the vhosts that need .htaccess.

You might do a:

find /etc/apache2 | xargs grep "AllowOverride None"

just to see if anything in your Apache folder is turning overrides off? Hope that helps. I know this stuff can be kind of maddening (and writing the rules themselves can be an entire new, uh, "process"!)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct