大家好,我的问题是..
我正在开发 codeigniter,我正在将所有网址重定向到一个 Controller 主页
在 application/config/routes.php 中使用此代码
$route['(.*)'] = "Home/index";
以及我想要使用不同 Controller 运行的任何其他文件
我做了这样的事情
$route['test/get']="test/get";
$route['test/index']="test/index";
在路由文件的末尾我添加这一行
$route['(.*)'] = "Home/index";
在家庭 Controller 内部我处理所有网址....
一切正常
我的 .htaccess 文件如下所示
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
现在我的问题是
我有旧网站 http://www.example.com/
所有页面都是简单的 php 页面,例如
http://www.example.com/one.php
http://www.example.com/two.php
http://www.example.com/three.php
此代码在没有任何 php 框架的情况下运行
现在具有相同域的新站点 http://www.example.com/
在没有 .php 扩展名的 php 框架 codeigniter 上运行
http://www.example.com/one
http://www.example.com/two
http://www.example.com/three
现在所有这些页面或网址都由一个 Controller 处理
现在我想要什么每当任何用户在谷歌或任何其他搜索引擎中搜索时,他们都会找到类似的链接
http://www.example.com/one.php
当他们点击此链接时...
我们应该将它们重定向到
http://www.example.com/one
我们怎样才能做到这一点
编辑
我有一个子路由,所有子路由也可以从一个 Controller 工作
http://www.example.com/one/x/y
http://www.example.com/two/p
http://www.example.com/three/q/r/s
我想从网址末尾删除 .php
最佳答案
在 .htaccess 文件中尝试此操作
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
希望对你有帮助...
关于php - htaccess 带有 .php 的旧文件 没有 php 的新文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39465992/