在CodeIgniter中重定向整个站点不起作用

问题描述 投票:-2回答:2

我需要将整个站点重定向到特定的控制器(under_construction),但我不想在所有页面中放入要重定向的脚本。

我想,我可以在.htaccess或CodeIgniter的routes中做到这一点。在.htaccess中,我不知道如何使用regex或如何使用它。

有了routes,我尝试了以下方法:

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

但这不起作用。没有显示任何响应,没有做任何我期望的事情,所有页面都转到under_construction控制器。我想为很多控制器做这个。使用regex有一种简单的方法吗?

php regex .htaccess codeigniter routes
2个回答
2
投票

这对我来说很有用.htaccess:

RewriteEngine On
RewriteBase /

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

您确实希望使用.htaccess以获得最佳性能,而302重定向则表示“此重定向不是永久性的,因此请稍后尝试相同的请求URI”。


0
投票

通过路由,您可以执行类似的操作。在APPATH.'config/routes.php'

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

在默认路径(安装附带)之后设置此路由。

© www.soinside.com 2019 - 2024. All rights reserved.