.htaccess - 使用 Codeigniter 临时关闭站点(301 可能使用 routes.php?)

标签 .htaccess codeigniter mod-rewrite redirect seo

我将 Codeigniter 与标准的 .htaccess 重写规则一起使用,因此在 url 中看不到/index.php/。

现在我最近需要暂时关闭网站,因此想将所有人重定向到“关闭”页面。以下工作:

$route['default_controller'] = "down";
$route['(:any)'] = "down";

但我知道在这种情况下,301 非常合适。

我应该如何以及在哪里设置它?我没有看到在 routes.php 中指定它的方法,并且由于现有规则而对如何在 .htaccess 中执行它感到困惑....

RewriteBase /

RewriteCond %{REQUEST_URI} ^_system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^myapp.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond $1 !^(index\.php|resources|files|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 

最佳答案

您不需要 301 重定向。 301 表示“永久”,这应该只是临时重定向。如果您将此添加到所有其他规则之上,则可以使用 htaccess 执行此操作:

RewriteRule ^ /down.html [L,R=302]

只要它高于任何其他规则,那么任何请求都将被重定向到 /down.html。如果您不想从外部重定向浏览器(例如,让 /down.html URL 显示在 URL 地址栏中),则删除 ,R=302方括号中的位和 URL 地址栏将保持不变,而提供的内容来自 down.html。

关于.htaccess - 使用 Codeigniter 临时关闭站点(301 可能使用 routes.php?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12963515/

相关文章:

php - .htaccess 多 View 在控制 Web 面板服务器中不起作用

php - 如何找到给定数组的可能子集?

php - 一些字符在 POST 期间编码,而另一些则没有

Apache > 如何分别重定向主页和其他网址?

Apache docker 容器 - .htaccess 重写规则 404

php - 多语言站点的 .htaccess 规则

apache - RewriteLog 触发内部服务器错误

apache - htaccess - 从 url 中删除 .php 扩展名

PHP - .htaccess 重写外部服务器连接

codeigniter - CodeIgniter 中的自定义异常