1

I need to redirect all requests concerning a folder to another (old) web server called www2 keeping the entire original path, for example

https://www.example.org/thisfolder/maps/map.jsp?id=2345 must be redirected to https://www2.example.org/thisfolder/maps/map.jsp?id=2345

I think the solution is to use the mod_rewrite module with RewriteRule directive and should be quite simple, but I cannot find a working example. I tried with

<IfModule !mod_rewrite.c>
    LoadModule rewrite_module  modules/mod_rewrite.so
</IfModule>
<Directory "/thisfolder">
    RewriteEngine On
    RewriteBase "/thisfolder"
    RewriteRule "(.*)" "https://www2.example.org/$1"
</Directory>

This is an Apache2.4 installation running on Linux CentOS 7.6 (Red Hat Enterprise). Thank you so much for your help!

2 Answers 2

0

Note that such a simple redirect requirement is a text book case where you don't need mod_rewrite.

mod_rewrite should be considered a last resort, when other alternatives are found wanting. Using it when there are simpler alternatives leads to configurations which are confusing, fragile, and hard to maintain.

A simple Redirect directive will already be sufficient in your case:

 Redirect "/thisfolder" "https://www2.example.org/thisfolder"
2
  • Thank you HBruijn. So easy :)
    – Steph
    Jun 12 at 10:04
  • Indeed, not complicated at all. - Once you know where in the extensive documentation for Apache httpd you need to look though ;)
    – HBruijn
    Jun 12 at 10:26
0

The <Directory> directive works for filesystem paths, not URL paths, so we need to change it to <Location> and also we have to capture properly the the request after "thisfolder/".

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule "^/thisfolder/(.*)" "https://www2.example.org/thisfolder/$1" [R=301,L]
</IfModule>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .