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]
- mod_rewrite is enabled
- AllowOverride All is enabled
- i tested my regexp https://regex101.com/r/jN2kA7/1
- RewriteRule ^.*$ maintenance.htm [R=302,L] strangely redirect to http://myserver/var/www/wiki/maintenance.htm
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]
This seems to work:
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:
would redirect to this (with test1 and double /):
whereas under my example this will redirect to:
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.