-2

I need to redirect an entire site to a specific controller (under_construction), but I do not want to put in all the pages a script to redirect.

I think, I might be able to do it in the .htaccess or in the routes of CodeIgniter. In the .htaccess I do not know how to work with regex or how to do it.

With routes I have tried the following:

$route['index.php/test'] = "under_construction";

But this doesn't work. Does not shows any response, doesn´t do anything of that I expected, that all pages go to the under_construction controller. I want to make this for a lot of controllers. Is there an easy way of doing this with regex?

Mary
  • 197
  • 1
  • 15
  • looks like you want redirect all your controllers to under construction page? you can use 'hooks'. – ichadhr Aug 22 '17 at 17:12
  • @ichadhr yes, that is what I want, redirect all my controllers to under construction page, but I do not know how use hooks – Mary Aug 22 '17 at 17:57
  • 1
    Including `index.php` in routes is wrong. Please check the [docs](https://www.codeigniter.com/user_guide/general/routing.html). – Tpojka Aug 22 '17 at 20:33

2 Answers2

2

This works for me in .htaccess:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !index.php/under_construction$ [NC]
RewriteRule ^(.*)$ http://localhost/index.php/under_construction [L,R=302]

You really want to use .htaccess for best performance, and the 302 redirect says, "This redirect isn't permanent, so try the same request URI later".

Brian Gottier
  • 4,522
  • 3
  • 21
  • 37
0

With routing, you can do something like this. In APPATH.'config/routes.php':

$route['(:any)'] = 'wanted/controller/method';

Set this route just after default ones (that came with installation).

Tpojka
  • 6,996
  • 2
  • 29
  • 39
  • Imagine for a minute the duplicate content penalization by Google whenall of your pages look the same... – Brian Gottier Aug 23 '17 at 15:00
  • You are right. Best would be to set variable in `index.php` file and check in, say, `APPPATH.'core/MY_Controller.php` for such a constant and load that specific landing page. – Tpojka Aug 23 '17 at 16:05
  • How is that any different than your routing solution? – Brian Gottier Aug 23 '17 at 16:30
  • I meant actually of redirecting (or remapping) to specific `controller/method`. maybe better redirect since response status can be set. And answer here is just to show usability of routes not seen as best solution. I would go with your one probably. – Tpojka Aug 23 '17 at 16:33