0

There are plenty of HTACCESS maintenance mode redirects here on stack overflow but I have yet to find one which will work for my structure.

I would like to redirect www.example.com to www.example.com/sub/maintenancemode.html. However I would still like to have access to subdomain.example.com. Subdomain will be used for dev and staging purposes etc

dbc
  • 104,963
  • 20
  • 228
  • 340
Richy
  • 167
  • 3
  • 13
  • You will also need to block `subdomain` somehow, otherwise it could get indexed. You could use the same code and simply block everything from everyone, except for a select few IPs? – MrWhite Jan 13 '16 at 15:48

2 Answers2

1

Here is your .htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^subdomain\.example\.com$
RewriteRule ^.* /sub/maintenancemode.html?
Florian Lemaitre
  • 5,905
  • 2
  • 21
  • 44
  • thanks for your response. Ended up using the code below. :) – Richy Jan 15 '16 at 08:25
  • Then you can mark my response or yours as answer to close this thread. [How does accepting an answer work ?](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – Florian Lemaitre Jan 15 '16 at 08:45
0

Ended up using this in the end

RewriteEngine On
RewriteBase /

RewriteRule ^(dev|staging)($|/) - [L]
RewriteCond %{REQUEST_URI} !/maintenance/coming-soon.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance/coming-soon.html [R=302,L]
Richy
  • 167
  • 3
  • 13