duanduo7400 2010-06-30 20:34
浏览 42
已采纳

CakePHP的路由是否会破坏我的.htaccess 301重定向?

I just migrated a site to an updated version, but want to put 301 redirects in place for some of the most common entry pages of the site to their counterparts

So here's the rule I'm adding to the .htaccess:

Redirect 301 /oldhomepage.htm http://www.thesite.com/

It sort of works, but it redirects to

http://www.thesite.com/?url=oldhomepage.htm

Is this some conflict with a CakePHP routing setting?

EDIT: Someone pointed out that it's probably an .htaccess conflict and indeed it is. CakePHP automatically creates an .htaccess file (which was in a child directory) that has the following:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Is there any way I can easily have the best of both worlds and have my simple, per page 301 redirects and keep CakePHP's routing as well?

  • 写回答

2条回答 默认 最新

  • duan19805 2010-07-01 00:27
    关注

    If all of the old URLs end with .htm, and none of your new URLs do, you could edit the CakePHP .htaccess file like so:

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

报告相同问题?

悬赏问题

  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决