在完成之后,我努力(因为托管公司,godaddy)index.php?从我的网站的 URL 中删除。
之后,我注意到一些用户正在使用旧 URL(带有 的 URL index.php?/)访问我的网站所以,我尝试使用301
重定向重定向
来自index.php?页面的用户,但没有运气。
我在互联网上搜索了一下,
但我认为问题背后的原因是我需要它从
包含或指向同一页面请求但没有(首选)的所有URL重定向。index.php?/example.comindex.php?/
例如:请求example.com/index.php?/site/category/etc将导致example.com或example.com/site/category/etc(首选方法)。
并且任何其他 URL 都将被视为相同。
这是我当前的.htaccess文件(与此问题无关):
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
更新:
尝试 php 解决方案:(Robin Castlin 的学分)
我尝试使用钩子(基于答案),但没有奏效!hooks我从配置启用,URL助手是自动加载的。
这个函数在里面application/hooks/MY_hooks.php:
function redirectToNewURL(){
if(preg_match('~/index.php?/~', $_SERVER['REQUEST_URI'])) {//check if the URL has index.php
header('Location: '.current_url(), true, 301); //redirect
exit;
}
}
这就是我设置钩子的方式:
从application/config/hooks.php
我放这个简单的数组开始:
$hook['pre_controller'] = array(
'class' => '',
'function' => 'redirectToNewURL',
'filename' => 'MY_hooks.php',
'filepath' => 'hooks'
);
最后,我没有得到任何结果。