Apache mod_rewrite does not work with .htaccess file

Ok, I had some problems with aws or something like that I cannot get mod_rewrite to work.

Just for testing, I did the following:

1 uses the aws console to deploy a new 64-bit ami instance from the wizard

2 yum installed apache

3 edited /etc/httpd/conf/httpd.conf: so that

<Directory /> Options FollowSymLinks AllowOverride None </Directory> 

looks like

 <Directory /> Options FollowSymLinks AllowOverride All </Directory> 

4 made sure that

 LoadModule rewrite_module modules/mod_rewrite.so 

is in the file and uncommented.

5 restarted apache:

  sudo /sbin/service httpd restart 

6 created two new files:

 /var/www/html/test1.html 

contains:

 this is test1! /var/www/html/test2.html 

contains:

 this is test2! 

7 created file:

 /var/www/html/.htaccess 

contains (IN TOTAL):

 RewriteEngine on RewriteRule ^test1\.html$ test2.html [L] 

8 went to:

 http://[my aws server]/test1.html 

I get "this is test1!"

I am doing something wrong here, but for the life of me I have no idea what. Any help is much appreciated ...

EDIT: I added meaningless characters / numbers to the top of my .htaccess file and restarted apache (not 100% sure it was necessary, but what the hey ...) and nothing happened. In other words, I expected that switching to url [aws server] /test1.html would lead to some error, but it is not. I suspect apache is not even reading the .htaccess file.

EDIT: I added the following to the httpd.conf file:

 RewriteLog "/tmp/rewrite.log" RewriteLogLevel 9 

The file is created when I restart apache, but nothing happens there when I go to any page that I installed. I cannot do something very, very basic here, but I'm not sure that ...

+4
source share
3 answers

Not sure if this is the cause of your problems, but you should not be confused with

 <Directory /> Options FollowSymLinks AllowOverride None </Directory> 

and it should be something like this:

 <Directory /> Options FollowSymLinks AllowOverride None Deny from all </Directory> 

You should add the directory of your document root as another container :

 <Directory /var/www/html/> Options FollowSymLinks AllowOverride All Allow from all </Directory> 
+14
source

It took me a while to find this, but on some installations Apache will use several configuration files.

Look at " /etc/apache2/sites-enabled/000-default " and make sure AllowOveride set to All

+4
source

Give it a try. This work is for me. First, you need to make sure that the .htaccess file is placed in the correct directory. To do this, go to the sites folder and check which .conf files are included.

 cd /etc/apache2/sites-enabled ls 

Example: 000-default.conf

Then, go to the folder available for editing this .conf file.

 cd ../sites-available sudo gedit 000-default.conf 

Find in DocumentRoot and check the directory again. If you put the .htaccess file in /var/www/html/.htaccess so that this line looks like this:

 DocumentRoot /var/www/html/ 

Second, you need to change the <Directory> block as shown below.

  <Directory /var/www/html> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all # This directive allows us to have apache2 default start page # in /apache2-default/, but still have / go to the right place #RedirectMatch ^/$ /apache2-default/ </Directory> 

Finally, you save the file and restart apache

 service apache2 restart 

Hope this help!

+2
source

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


All Articles