URL重写不起作用(ubuntu13.10 / apache2.4.6)

I need your help! (sorry for my bad english)

I try to do url rewriting in my localhost on Ubuntu13.10/Apache2.4.6 ... I searched a lot of time on internet and problem is always here..

this is my .htaccess (I begin in url rewriting so I don't know if it's ok) :

RewriteEngine On
AllowFromAll All
RewriteRule home/   index.php?uc=home

and when I go to 127.0.0.1/mywebsite/home/ I have a 404 error.

  • My .htaccess is in : mywebsite/.htaccess
  • I activated url rewrite with "sudo a2enmod rewrite" and restarted apache.
  • I have no error in apache logs
  • I read solution who said I have to change AllowOverride to On in /etc/apache2/sites-available/default but I dont have /etc/apache2/sites-available/default file
  • I am lost...

Please, I don't know what to do...

After many tests : I think I have a problem of AllowOverride

You either need to specify the RewriteBase

RewriteBase /mywebsite/
RewriteRule home   index.php?uc=home [L]

or add it to your rule

RewriteRule /mywebsite/home   index.php?uc=home [L]

I think this is more like this :

RewriteRule is relative to the RewriteBase, so if your .htacess is in /mywebsite/ folder :

RewriteBase /
RewriteRule /home   index.php?uc=home [L]

this way it should work, let me know ;)

So... If this is not working, let's start by the beginning.

Find httpd.conf

LoadModule rewrite_module libexec/mod_rewrite.so and AddModule mod_rewrite.c should be in there, and without comment mark (#)

In your .htaccess, there is :

# The server must follow symbolic links (this can help in some apache versions)
Options +FollowSymlinks

# RewriteEngine activation
RewriteEngine on

# RewriteRule
RewriteRule ^home$   index.php?uc=home [L]

This configuration works on my apache 2.2.22.

The truth is that

/index.php?uc=home [L]

points on http://127.0.0.1/index.php

instead of http://127.0.0.1/mywebsite/index.php

because of the DocumentRoot property. On a real domain, or /w a virtualhost pointing on /mywebsite/, /index.php?uc=home [L] should work.

Keep in mind that RewriteRule is relative to the DocumentRoot and RewriteBase can't resolves this problem.