0

i'am trying to do a simple redirect to a maintenance page, but seems like apache won't let me do !

i have a folder for 3 version of a wiki (each with a specific language), so i want to redirect each wiki trafic to his own maintenance page.

here is my .htaccess

 #Redirect trafic to maintenance page RewriteEngine On RewriteCond %{REQUEST_URI} !maintenance.htm$ [NC] RewriteRule "(.*\/wiki.*\/).*" "$1/maintenance.htm" [R=302,L] 

the goal is to redirect "myserver/wiki/ANYTHING" to "myserver/wiki/maintenance.htm"

if someone could tell me what i am doing wrong, it would be nice

Thanks

Edit:

After some more test, seems like i am looking for something like that

RewriteRule "(.*)" "??PROTOCOL??://%{HTTP_HOST}/??SITEFOLD??/maintenance.htm" [R=302,L] 
1

1 Answer 1

1

This seems to work:

#Redirect trafic to maintenance page RewriteEngine On RewriteCond %{REQUEST_URI} !maintenance.htm$ [NC] RewriteRule "(.*\/wiki)\/.*" "$1/maintenance.htm" [R=302,L] 

Your version allows the / to be matched by the .* as well (as Apache is greedy regexpr) and also including the / in the bracket means it's repeated. So under your example:

myserver/wiki/test1/test2 

would redirect to this (with test1 and double /):

myserver/wiki/test1//maintenance.htm 

whereas under my example this will redirect to:

myserver/wiki/maintenance.htm 

Which I think is what you want.

However, even though my solution above should work, sometimes it might be better to just simplify this for your own sanity and just have three of them. While it is a bit of repetition and is not scalable, if you are limited to three then sometimes clarity is better than cleverness. For example if you have an English wiki, a Spanish Wiki and a German wiki at /en/wiki, /es/wiki and /de/wiki respectively, then the following might just be easier.

#Redirect trafic to maintenance page RewriteEngine On RewriteCond %{REQUEST_URI} !maintenance.htm$ [NC] RewriteRule "/en/wiki/.*" "/en/wiki/maintenance.htm" [R=302,L] RewriteCond %{REQUEST_URI} !maintenance.htm$ [NC] RewriteRule "/es/wiki/.*" "/es/wiki/maintenance.htm" [R=302,L] RewriteCond %{REQUEST_URI} !maintenance.htm$ [NC] RewriteRule "/de/wiki/.*" "/de/wiki/maintenance.htm" [R=302,L] 
4
  • that s exactly what i need, i tried, and it won't work on my server, i found something really strange: each time i set $1 the redirect won't works ... i am trying to get rewrite log, but it changed in apache 2.4 so i have to search about it too xd Commented Sep 23, 2015 at 11:33
  • So does the second more explicit option work? Commented Sep 23, 2015 at 11:38
  • yes it is the $1 who wont work, even RewriteBase "/wiki/" won't work Commented Sep 23, 2015 at 11:39
  • there was two <virtual> in conflict, so now all is working thanks ! Commented Oct 9, 2015 at 14:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.