Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache rewrite rule

I want to redirect "http://localhost/b.html" --> "http://localhost/a.html" I tried RewriteRule for that. But somehow it is not working 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 tri "http://localhost/a.html" It shows me the web page. But when I triend "http://localhost/b.html" apache2/error_log says "file does not exist: b.html" Does any setting missing to enable rewrite_module?

like image 434
ashweta Avatar asked Sep 22 '26 16:09

ashweta


1 Answers

The problem is in your RewriteRule. this should work:

RewriteEngine On
RewriteRule ^/b.html$ /a.html [L]
  1. the rule match (^b.html$) must not include the starting slash. (this works in .htaccess, but not in server config)
  2. the rewrite target should be a relative URI if possible (i.e. on the same host)
  3. the rule should end with a directive "what to do" - in this case [L]eave processing (no more rules will be processed)
like image 109
Piskvor left the building Avatar answered Sep 24 '26 06:09

Piskvor left the building



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!