0

I am writing a .htaccess to be able to softly update my website, preventing new coming users to access it, and already connected users to be softly redirected, taking account that there are some image rollovers, css styles and async PHP and js calls in the process that can be called within a displayed page without needing to reload a new page from the web site.

Just redirecting anything to an update.php page would generate some unwanted effects on the pages that contains such things.

So I am fighting since days to find the correct set of rules to put in my .htaccess to achieve the following goal. Can you help me ?

If specialpage.php is called (even with parameters) redirect to specialpage_redirected.php

If specialpage2.php is called (even with parameters) redirect to specialpage2_redirected.php

if any other php file is called (even with parameters) redirect to redirected.php

If specialscript.js is called redirect to specialscript_redirected.js

If any other .js is called redirect to redirected.js

and let all other files be accessed (css, images, ...)

... or if you have a better solution to achieve this goal to put the site offline for a maintenance, taking the previous constraints (already connected users on dynamic pages) into account.

dbc
  • 104,963
  • 20
  • 228
  • 340
Oliver
  • 23,072
  • 33
  • 138
  • 230

1 Answers1

0

Place these rules in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

RewriteRule ^(specialpage2?)\.php$ $1_redirected.php [L,NC]

RewriteCond %{REQUEST_URI} !^/specialpage [NC]
RewriteRule \.php$ redirected.php [L,NC]

RewriteRule ^(specialscript)\.js$ $1_redirected.js [L,NC]

RewriteCond %{REQUEST_URI} !^/specialscript [NC]
RewriteRule \.js$ redirected.js [L,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thank you, I will try this. Do these statements take possible php page parameters into account, like page.php?i=1&b=test ? The $ just after "php" let me think that they don't. – Oliver Jul 28 '14 at 18:11
  • Yes parameters will be rewritten as is. Query string is not matched in `RewriteRule` hence presence of `$` is only to match `/page.php`. Query string is automatically passed over to target URI. – anubhava Jul 28 '14 at 18:13