I know that this question have been asked several times. But I can\'t get it to work.
I installed Apache2 in my Ubuntu server I can also confirm that mod_rewrite is
Please check /etc/apache2/apache2.conf
Because this thread ranks very high on google, here another solution:
WHAT'S CAUSING THE PROBLEM ?
It's caused because the standard definition in apache simply blocks all .htaccess stuff. Seriouslsy. This seems to be the initial state in Ubuntu 12.04 LTS.
SOLUTION
In /etc/apache2/sites-available/default (that's a file, not a folder) there's a code block like
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride XXXXXXXXXXXXXXXXXXX
Order allow,deny
allow from all
</Directory>
Here you should change
AllowOverride None
to
AllowOverride All
IMPORTANT
You have to do these changes with sudo rights, anotherwise Ubuntu will not save the file. After a RESTART your .htaccess stuff should work. To test .htaccess simply put some nonsense text into it and surf to localhost or 127.0.0.1 -> If you see "internal server error": voila! Remove the nonsense and you are ready to go.
All suggestions from Niels Bom are the smartest ones (I think). But I would add this as the first suggestion: try to launch and stop apache via the Ubuntu command: then when it's supposed to be stopped, make sure it's stopped ie verify your local page doesn't show anymore.
/etc/apache2/
. There should be apache2.conf conf.d envvars httpd.conf mods-available mods-enabled ports.conf sites-available sites-enabled
mods-enabled
where you will find if the mods are enabled if so, then you can go on, otherwise take a look at the other answers about enabling modrewritesites-enabled
: it's where you can find the sites that are... (guess what?) enabled. There should be the default
website.<virtualhost>
- </virtualhost>
tags (of course).Please tell me what's going on and I'd be glad to update my question accordingly.
Okay, let's check assumptions:
Put nonsense in your Apache config files (and restart Apache to let them take effect), does Apache "complain" on restart? Then it tries to load those files. Try this for every Apache config file you can find. You now have a complete list of Apache config files that are loaded.
put nonsense in your htaccess, reload the page, do you get a 500 error? If not, the htaccess is not getting loaded.
Put the most basic mod_rewrite statement in your htaccess:
Options +FollowSymLinks RewriteEngine On RewriteRule ^.*$ test.html
This should rewrite every request to test.html.
Try this and give us the results.
if you run this command,
sudo a2enmod rewrite
ubuntu will output whethere it is activated or already running.
In your question, you have mentioned,
Also, my apache2.conf file doesn't work. I tried to write som nonsense. And it is still gives me the normal result instead of http 500 error
So, before posting more stuff to try-out with .conf files,
run strace -o somefilename.txt sudo /etc/init.d/apache restart
strace - trace system calls and signals : strace(1) - Linux man page.
The -o somefilename.txt
part puts the output of strace
into somefilename.txt
. Open the text file and search for httpd.conf
. You should be able to see code similar to:
stat("/etc/httpd/conf/httpd.conf", {st_mode=S_IFREG|0644, st_size=35894, ...})=0
open("/etc/httpd/conf/httpd.conf", O_RDONLY|O_CLOEXEC) = 3
The path to httpd.conf
will be replaced by the path to your default httpd.conf
If you find one, then open that httpd.conf
and make changes there. Else, a httpd.conf
is not getting loaded.
If later is the case, try:
sudo /etc/init.d/apache -f /path/to/httpd.conf start
Also, check for NameVirtualHost *:80
and make sure it is not commented.