RewriteRule in .htaccess not working

I am currently running Apache2 on my local computer installed with the latest version of Ubuntu.

I am trying to get a basic URL rework using a .htaccess file.

The file " http: //localhost/page.php? = Home " exists, but the location "/ doesnotexist / home" does not work.

I would like the first page to load when the second is requested.

My .htaccess file looks like this:

RewriteEngine On RewriteRule ^/doesnotexist/(.*)$ /page.php?p=$1 

My httpd.conf file looks like this:

 LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so <Directory /var/www> AllowOverride All </Directory> 

Please note that my httpd.conf file looks the same as it was empty before I edited it.

As a result, I get the following:

 Not Found The requested URL /doesnotexist/home was not found on this server. 

I am from this problem googled from life, and I have never received anything but the error above.

If anyone has any ideas, I would be very grateful.

+4
source share
3 answers

In the interest of others, I understood the answer:

In the file "/ etc / apache2 / sites-enabled / 000-default" there was a line:

 AllowOverride None 

Change this to:

 AllowOverride All 
+19
source

You need to remove the context path prefix from your template when using mod_rewrite in the .htaccess file. In the root directory, the path prefix is / . So try the following:

 RewriteRule ^doesnotexist/(.*)$ /page.php?p=$1 
+2
source

If I put .htaccess in / Library / WebServer / Documents and open "localhost /"; To test this, it works as expected. It just doesn't work in "~ / Sites". I tried this on Mac OS X Mavericks.

0
source

Source: https://habr.com/ru/post/1300212/


All Articles