View Full Version : How to enable mod_rewrite in Ubuntu server??
zoon_unit
September 11th, 2006, 05:09 PM
I'm trying to find the right way/file to enable mod_rewrite. I know the typical place to do this is in httpd.conf, but of course Ubuntu has its own funky way of doing this with the mods-available and sites-available conf files.
What's the official way to enable mod_rewrite on Ubuntu?
tbonius
September 11th, 2006, 05:34 PM
I assume you are talking about Apache2 directory structure for Ubuntu. This is the new and modular way all distributions will be laying out their Apache2 server config.
Mod_rewrite is compiled in by default. You can see it in the /etc/apache2/mods_available directory. If you feel like making doubly sure that it is loaded then simply put the following directive into httpd.conf:
LoadModule mod_rewrite /usr/lib/apache2/modules/mod_rewrite.so
You can verify what modules are loaded with:
sudo apache2ctl -l
T
zoon_unit
September 11th, 2006, 08:13 PM
I actually found the following command that did the trick:
a2enmode rewrite
StFS
September 21st, 2006, 02:18 PM
And for future references, the "correct" way to define a new site (such as a new virtual host) is to create the definition in /etc/apache2/sites-available in its own file and then call:
a2ensite conf_file_name
to enable it.
ookadoo
August 25th, 2007, 06:09 PM
I actually found the following command that did the trick:
a2enmode rewrite
The correct program name is a2enmod as in "apache2 enable module <module>":
a2enmod rewrite
Pekz0r
September 1st, 2007, 08:53 AM
I'm also looking for a way to enable the rewrite mod to apache2.
i ran the commmand a2enmod rewrite and it said that the mod was addess successfully, but i can't see it in the list when i type: sudo apache2ctl -l
I've tried to make a rewirie rule to test but i'm not sure how to do it. This is what i've done:
In apache2.conf:
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
In .htaccess (in var/www/mysite):
RewriteEngine on
RewriteRule /page/([0-9]+) /page.php?page=$1
It does not work. What have i done wrong?
wasert
September 4th, 2007, 03:34 AM
I am having the same problem.
mod_rewrite is enabled
a2enmod rewrite
I edited my /etc/apache2/apache2.conf and added the following lines (following Plone's guide):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/(.*) http://localhost:8080/$1 [P]
</IfModule>
I tried adding a very simple RewriteRule and still didn't work
Pekz0r
September 4th, 2007, 03:43 AM
I've found out the solution!
Change AllowOverRide None in /etc/apache/sites-available/default to AllowOverRide All(or something else, but not None). Apache won't read the rewrite rules nor the .htaccess-files if AllowOverRide is set to None.
Hope that helps you too!
wasert
September 4th, 2007, 03:56 AM
still doesn't work
:(
thanks for your help though
Pekz0r
September 4th, 2007, 04:00 AM
Is mod_rewite in the list loaded modules in phpinfo()?
Try putning the rewrite rules in a -htaccess file, that works for me
wasert
September 4th, 2007, 01:25 PM
I am not using PHP, but I try the following command, and mod_rewrite appears to be loaded.
$ sudo apache2 -M
Loaded Modules:
core_module (static)
log_config_module (static)
logio_module (static)
mpm_worker_module (static)
http_module (static)
so_module (static)
alias_module (shared)
auth_basic_module (shared)
authn_file_module (shared)
authz_default_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
cgid_module (shared)
dir_module (shared)
env_module (shared)
mime_module (shared)
proxy_module (shared)
rewrite_module (shared)
setenvif_module (shared)
status_module (shared)
jrun_module (shared)
Syntax OK
I tried your suggestion and I changed the following:
First, I changed the following line in /etc/apache2/sites-enabled/000-default
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/>
Options FollowSymLinks
AllowOverride all
Order allow,deny
allow from all
</Directory>
And then, I placed a .htaccess file in /var/www with the following contents
$ cat .htaccess
RewriteEngine On
RewriteRule ^/(.*) http://localhost:8080/$1 [P]
After restarting apache, mod_rewrite still doesn't do anything.
Thanks for your help
socceroos
October 22nd, 2007, 11:05 PM
I know this may sound silly. But try changing 'AllowOverride all' to 'AllowOverride All'.
I have known apache to be pedantic about this sort of thing before.
gorkau
October 25th, 2007, 02:57 AM
I had the same problem and the AllowOverride All solution worked fine for me. Here is what I did:
1) sudo a2enmod rewrite
2) sudo gedit /etc/apache2/sites-enabled/000-default
3) Change AllowOverride None to AllowOverride All
4) Restart Apache: sudo /etc/init.d/apache2 force-reload
And that's all!
Delphinus
December 2nd, 2007, 06:05 AM
I had to disable multiviews to get my .htaccess overrides working properly.
theolster
December 6th, 2007, 07:59 AM
I could really do with some help on this too. I'm trying to install Durpal on my server, which would work a lot better if mod_rewrite is enabled.
sudo apache2 -Mreturns thisapache2: illegal option -- M
but this works (and shows that mod_rewrite is not included)
$ sudo apache2 -l
Compiled in modules:
core.c
mod_access.c
mod_auth.c
mod_log_config.c
mod_logio.c
mod_env.c
mod_setenvif.c
prefork.c
http_core.c
mod_mime.c
mod_status.c
mod_autoindex.c
mod_negotiation.c
mod_dir.c
mod_alias.c
mod_so.c
yet I also get this result$ a2enmod rewrite
This module is already enabled!
I'm very confused and could do with some help getting this to work!
adster101
December 18th, 2007, 09:00 PM
I was getting the same as above. But I amended the sites-enabled file to AllowOverride All and my .htaccess file started to work.
He he, very good.
evilninjamaster
January 15th, 2008, 05:34 AM
The /etc/apache2/sites-enabled/000-default edit worked for me, too, although I think only the
<Directory /var/www/>
Options FollowSymLinks
AllowOverride all
Order allow,deny
allow from all
</Directory>
edit is necessary, not
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
One more thing: after a lot of jiggery-pokery (trying different things), I had erroneously put the RewriteLog tag in the .htaccess file, where it is not allowed. My apache error.log usefully prints out:
... [alert] [client 127.0.0.1] /var/www/.htaccess: RewriteLog not allowed here
I had to correct the problem (move the tag to apache2.conf) before mod_rewrite started working.
Looks like Apache will disable mod_rewrite if you have any similar errors, so it's worth checking your apache error.log.
mahalie
January 17th, 2008, 11:33 PM
I had the same problem and the AllowOverride All solution worked fine for me. Here is what I did:
1) sudo a2enmod rewrite
2) sudo gedit /etc/apache2/sites-enabled/000-default
3) Change AllowOverride None to AllowOverride All
4) Restart Apache: sudo /etc/init.d/apache2 force-reload
And that's all!
Yeah, for all you other newbs like me who tried to enable rewrite mod 7,000 times and even considered reinstalling flippin apache, make sure you set AllowOverride All in sites-enabled instead of messing with httpd.conf. Dang, I just wasted an hour, but on the happy side, I learned about kill (http://23rdworld.com/2008/01/17/kill-is-your-friend/)!
yasar
May 14th, 2008, 04:21 AM
This worked for me.. Thanks..
I've found out the solution!
Change AllowOverRide None in /etc/apache/sites-available/default to AllowOverRide All(or something else, but not None). Apache won't read the rewrite rules nor the .htaccess-files if AllowOverRide is set to None.
Hope that helps you too!
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.