Apache rewrite rule

I want to redirect " http: //localhost/b.html " β†’ " http: //localhost/a.html " I tried RewriteRule for this. But for some reason this does not work for me.

I am using apache2, and my httpd.conf contains:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule rewrite_module modules/mod_rewrite.so

RewriteEngine On
RewriteRule ^/b.html$ http://localhost/a.html

When I three " http: //localhost/a.html " He shows me a web page. But when I triend " http: //localhost/b.html " apache2 / error_log says "file does not exist: b.html" Is there any setting to enable rewrite_module?

+3
source share
4 answers

RewriteRule. :

RewriteEngine On
RewriteRule ^/b.html$ /a.html [L]
  • (^b.html$) . ( .htaccess, )
  • URI, (.. )
  • " " - [L] eave ( )
+5

, Apache ( httpd.conf) Alias ​​ VirtualHost:

AllowOverride All

, modrewrite, , :

AllowOverride None

.

+3

virtualhost?

<VirtualHost *:80>
    RewriteEngine On
    RewriteRule ^/b.html$ /a.html
</VirtualHost>
+1

. :

  • "AllowOverride None" /etc/apache 2/sites-available/default "AllowOverride All".

  • Put the rewrite rule in /var/www/.htaccess instead of httpd.conf

I am not sure why it does not work in httpd.conf. But it works after doing the above two things.

+1
source

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


All Articles