Mary Mary - 1 month ago 7
PHP Question

Redirect an entire site in CodeIgniter does not work

I need to redirect an entire site (all the controllers) to a specific controller, 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
?

Answer Source

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".