views:

92

answers:

4

hi,

I was wondering what's the best way to switch a website to a temporary "under costruction" page and switch it back to the new version.

For example, in a website, my customer decided to switch from Joomla to Drupal and I had to create a subfolder for the new CMS, and then move all the content to the root folder.

1) Moving all the content back to the root folder always create some problems with file permissions, links, etc...

2) Creating a rewrite rule in .htaccess or forward with php is not a solution because another url is shown including the top folder.

3) Many host services do not allow to change the root directory, so this is not an option since I don't have access to apache config file.

Thanks

Update: I can maybe forward only the domain (i.e. www.example.com) and leave the ip on the root folder (i.e. 123.24.214.22), so the access is finally different for me and other people? Can I do this in .htaccess file ?

A: 

One way would be the use of an include on your template page.
When you want the construction page to show, you set a redirect in the include to take all traffic to the construction page.

When you are done your remove the redirect.

WebDude
mhm where is this template page located ? You mean in the root folder ? The point is that if I forward all the traffic, I cannot access anymore to the CMS installed in the root folder to configure it, right after I moved it. And even if I can access to back-end, I cannot check if everything is fine before to show it to the public.
Patrick
A: 

What I did when I used PHP for websites was to configure Apache to direct all requests to a front controller. You then would have full access to all requests no matter where they are pointing to. Then in your front controller (PHP file, static html file, etc.), you would do whatever you need to do there.

I believe you need to configure pathinfo in Apache and some other settings, it has been about 3 years since I have used that approach. But, this approach is also good for developing your own CMS or application so that you have full control over security.

You have to do something similar to this: http://www.phpwact.org/pattern/front_controller

I am looking for more details, I know my configuration had more to it than that.

This is part of what I'm looking for too: http://httpd.apache.org/docs/2.0/mod/core.html

Enabling path_info passes path information to the script, so all requests now go through a single point of entry. Let me find my configuration, I know vaguely how this works, but I'm sure it looks like a lot of hand waving.

Also, keep in mind that because all requests are going through this single PHP file, you are responsible for serving images, JavaScript, CSS, etc. So, if a requests is coming in for /css/default.css, that will go through your php script (index.php, most likely), then you'll need to determine how to handle the request. Serving static files is trivial, but it is a little more work.

If you don't want to go that route, you could possibly do something with mod_rewrite so that it only looks for .html, .htm pages or however you have your site configured. For me, I don't do extensions, so that made my regex a little more difficult. I also wanted to secure access to all files. The path_info was the solution for me, but if you don't need that granularity, then writing a front controller might be a bit too much work.

Walter

mhm sorry could you elaborate more the part about the "front controller" ? What is that exactly ? I guess what I need here is an Apache functionality allowing me to see the website in the root folder from an alternative path (forwarding), and keep at the same time a public temporary page (alternative view) in the root folder for the public.
Patrick
I would have to look to see exactly how I did it. It passes all requests through that controller. It is an Apache configuration that basically tells Apache to use this file, script, whatever no matter what request is coming in. I think the pathinfo is what you want, let me do a quick look. Otherwise, I have my old website archived somewhere, I can pull that up in a day or so.
I just noticed too, if you don't have access to the apache configuration file, do you at least have the ability to control .htaccess? If you don't, well then, both of these options are no good. In my case, I used .htaccess as I was using a shared Apache instance.
yeah, I have access to .htaccess . But so far I only know the rewrite rule, which doesn't solve my problem. I don't get it, your solution seems not to be very common, right ? Then how usually people deal with this ? They accept to have their website down or visible to public for some time even if under configuration ?
Patrick
Oops, I totally forgot about looking up my configuration. I know I have it, but it is spanned on 3 dvd's in an archive file ... Yeah, my solution is not typical, but the front controller is a good design practice. That is my leading complaint with anyone developing a PHP website, you can easily break the site by typing in urls manually and getting a nasty error page served up by apache. Sites are typically only designed to handle users clicking on links. That would be my understanding. It all depends on what your requirements are. For me, it was important that I secure every page /file.
A: 

What about hijacking your index.php file?

Something simple, along the lines of

<?php
  if (SITE_OFFLINE)
    include 'under_construction.html';
  else
    //normal content of your index page
?>

where you would naturally define SITE_OFFLINE in an appropriate place for your needs.

espais
mhm yeah but still I cannot test my website before to make it public if it is in the same directory. For testing I mean access different pages, submit forms etc...
Patrick
+1  A: 

One thing to consider is you don't want search engines to cache your under construction page - and you also don't want them to drop your homepage from the search index either (Hence just adding a "noindex" meta tag isn't the perfect solution).

A good way to deal with this is do a 302 redirect (temporarily moved) from your homepage to your under construction page - that way the search engine does not cache your homepage as an under construction page, does not index your under construction page (assuming it has a NOINDEX meta tag), and does not drop your homepage from the search index either.

HipHop-opatamus
thanks nice tip. But how can I redirect everybody beside me ? I need to be the only one seeing my website to test it.
Patrick
You can do it by IP address, Cookie, or if you want to be a little sneaky just add a GET parameter (?letmein=1) which your script listens for to skip the redirect
HipHop-opatamus
hi, I cannot use the get parameter because it is already used by drupal to pass parameters to each page. Can you elaborate more this part ? "You can do it by IP address, Cookie," how exactly ?
Patrick