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


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]

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]
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
  • doukan6564 2010-06-30 23:16

    Why would you not use $this->redirect('http://www.thesite.com/', 301); in your controller?




  • ¥100 webapi的部署(标签-服务器)
  • ¥20 怎么加快手机软件内部计时的时间(关键词-日期时间)
  • ¥15 C语言除0问题的检测方法
  • ¥15 为什么四分管的内径有的是16mm有的15mm,四分不应该是12.7mm吗
  • ¥15 macos13下 ios交叉编译的问题
  • ¥15 bgz压缩文件怎么打开
  • ¥15 封装dll(引入了pcl的点云设计库)
  • ¥30 关于#开发语言#的问题:我需要在抄板的基础上再抄板抄程序,根据RDA8851CM基础上开发
  • ¥15 oracle 多个括号,怎么删除指定的括号及里面的内容?
  • ¥15 小新14API2019想用bios调风扇