Question

I am performing an update to a site and so I want to create a 302 temporary redirection for all webpages with the exception of one specific page.

perishablepress.com has two articles on the topic for which I am currently using option 1:

  1. http://perishablepress.com/temporary-site-redirect-for-visitors-during-site-updates/
  2. http://perishablepress.com/htaccess-redirect-maintenance-page-site-updates/

These article refer to amending all pages, where as I have one page I want to keep live. (As it goes I'm struggling to get option 2 to work at all). Can anyone tell me what is the best way to achieve this?

To clarify I would like to:

  1. Have all pages redirect to coming-soon.html (i.e. www.mywebsite.com/sample-page.html => www.mywebsite.com/coming-soon.html)
  2. Add an exception for /contact-us.html so that this request is processed normally (i.e. www.mywebsite.com/contact-us.html => www.mywebsite.com/contact-us.html)
Was it helpful?

Solution

You may try this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  !contact-us.html  [NC]
RewriteCond %{REQUEST_URI}  !coming-soon.html [NC]
RewriteCond %{REQUEST_URI}  \.(html|htm)/?    [NC]
RewriteRule .*  coming-soon.html              [R=301,L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top