SID-02108: How do I use an HTTP Rewrite to redirect to new server
| Status: |
Answered |
TWiki version: |
6.0.1 |
Perl version: |
5.018002 |
| Category: |
CategoryDeployment |
Server OS: |
Ubuntu 14.04.2 LTS |
Last update: |
10 years ago |
I am migrating my Twiki site from one machine to another. This is an internal system and is not accessible from outside the lan.
What I have been asked to do is write an http rewrite so that any existing links to the old site will go to the correct location on the new site. The paths to each are below.
https://oldserver/cgi-bin/twiki/view/Main/documentname
----- Old site
https://newserver/cgi-bin/twiki/view/Matrix/documentname
---- New Site
cgi-bin alias is: -
/usr/lib/cgi-bin/twiki - /cgi-bin
In the top of the document section of the apache2/sites-available/twiki.conf file I have the following
RewriteEngine on
RewriteRule ^/cgi-bin/twiki/view/Main/(.*)$ https://newserver/cgi-bin/view/Matrix/$1 [R=301,L]
It however does precisely nothing.
Just wondering if you have any clue what I am doing wrong?
--
Neil Roberts - 2015-10-05
Discussion and Answer
Make sure the
rewrite_module is loaded by Apache. The rewrite rule appries to the current directory where the rewrite rule is listed, e.g. you might need to just specify
view/Main/(.*)$ for the first parameter.
Alternatively install the
MovedSkin and set a MOVEDMESSAGE in the TWikiPreferences, it has been designed for this use case.
--
Peter Thoeny - 2015-10-05
This may be nitpicking, but if no additional conditions apply to your use case,
mod_rewrite seems like a bit of overengineering.
The simple apache way would be to use
Redirect, as provided by
mod_alias. So, instead of your
Alias or
ScriptAlias you can use:
Redirect permanent /cgi-bin/twiki/view/Main/ https://newserver/cgi-bin/twiki/view/Matrix/
The
permanent declaration causes a 301 status, like your rewrite rule.
Another nitpicking: There's an omission in your rewrite rule: The target URL is missing
twiki/ between
cgi-bin/ and
view. I guess that is not the problem, because this should result in a different symptom: a 404 response from
newserver.
--
Harald Jörg - 2015-10-05
Thanks very much Peter. I used your method and it worked perfectly. Thanks as well Harald for your suggestion. That is certainly one I will keep a note of for future reference.
--
Neil Roberts - 2015-10-06
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.