douxi8759 2016-09-13 08:57
浏览 69
已采纳

htaccess旧文件与.php新文件没有PHP

Hello everyone my problem is ..
I'm working on codeigniter i'm redirecting all my urls in one controller home

Using this code in application/config/routes.php

$route['(.*)'] = "Home/index";

And any other files that i want run with different controllers

I do something like this

$route['test/get']="test/get";
$route['test/index']="test/index";

And at the end of the route file i add this line

$route['(.*)'] = "Home/index";

Inside of home controller i handle all urls ....

Everything is working fine

My .htaccess file look like this

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Now my problem is

I have old site http://www.example.com/

All pages are simple php pages like

http://www.example.com/one.php  
http://www.example.com/two.php  
http://www.example.com/three.php  

This code is running without any php framework

Now new site with same domain http://www.example.com/
Running on php framework codeigniter without .php extension

  http://www.example.com/one
  http://www.example.com/two  
  http://www.example.com/three

Now all this pages or url is handle by one controller

Now what i want When ever any user search in google or any other search engine and they found link something like

http://www.example.com/one.php  

When they click on this link ...
We should redirect them to

http://www.example.com/one

How can we do that

Edit
I have sub route that all sub routes also working from one controller

  http://www.example.com/one/x/y
  http://www.example.com/two/p  
  http://www.example.com/three/q/r/s   

I want to remove .php from the end of the url

  • 写回答

2条回答 默认 最新

  • dt2015 2016-09-13 09:13
    关注

    You can grab the string before .php and then send a 301 redirect:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/?([\w\/_\.-]*)\.php$ /$1 [L,R=301]
    

    This way you tell the search engines to update links they have in their systems to use the new ones without losing any SEO reputation you build.

    Edit:

    RewriteCond %{REQUEST_FILENAME} \.php$
    

    You need to add this RewriteCond to the file to grab all new CodeIgniter routes. This would result in the following overall .htaccess file.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} \.php$
    RewriteRule ^/?([\w\/_\.-]*)\.php$ /$1 [L,R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能