Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to activate mod_rewrite?

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 installed using phpinfo();. I have also put a file called .htaccess in my root folder(/var/www/.htaccess). In my .htaccess file I paste the following code:

Options +FollowSymLinks 
RewriteEngine On 
RewriteRule ^.*$ test.php

So everything is redirected to test.php

But it still doesn't work. So I checked my httpd.conf file under /etc/apache2. It is completely empty, with no lines of code (This seems a little odd to me)?! However checking in Stackoverflow answers there should be at least the following code in httpd.conf:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
    Satisfy all
</Directory>

So I paste that code in httpd.conf. And restarted Apache with sudo /etc/init.d/apache restart. And it still does not work?

I have also tested to open the file /sites-enabled/000-default and /sites-available/default, where all virtual host settings lies and change under the directory /var/www and / to AllowOverride All. The mod_rewrite still doesn't work. Can anyone please help me. This problem has been baking my nuts for a while.

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

like image 271
einstein Avatar asked Dec 25 '11 08:12

einstein


1 Answers

if you run this command,

sudo a2enmod rewrite

ubuntu will output whethere it is activated or already running.

like image 150
bingjie2680 Avatar answered Oct 12 '22 19:10

bingjie2680