我将 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/