mod_rewrite的重定向如果没有找到文件 [英] mod_rewrite redirect if file not found

查看:167
本文介绍了mod_rewrite的重定向如果没有找到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用该流量重定向到特定的文件,所以我可以使用搜索引擎友好的URL但有关于这一点我不想流量导向离开现场的一些静态页面前端控制器网站:

目前,我有以下的.htaccess:

  RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ example.com [NC]
重写规则^(。*)$ http://www.exmple.com/$1 [L,R = 301]
ErrorDocument的404 /controller.php
 

这似乎是做工精细:

  • 在所有流量都被转移到 www.example.com ;
  • 与任何网页未发现被定向到 Controller.php这样来处理;
  • 在任何实际存在,如 www.example.com/about_us.php 仍然有效;

的问题是,它仍然报告404错误,即使在该页仍发送和正确显示 - 它看起来并不什么不同最终用户,但它搞乱了我的搜索引擎优化与谷歌的谷歌机器人看到404并假定没有什么别的那里。

有什么办法,我可以简单地重定向所有流量除了某些页面或列表中有没有更好的解决方案?

任何帮助,想法,意见等,将是最受欢迎的。

解决方案

  RewriteEngine叙述上
ErrorDocument的404 /controller.php

的RewriteCond%{HTTP_HOST} ^ example.com [NC]
重写规则^(。*)$ http://www.example.com/$1 [R = 301,NC]

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d

重写规则。*的index.php / $ 0 PT]
 

您应该通过index.php的路线......否则线下方应该工作的上面的一个替代。

 重写规则。* $ 0 PT]
 

I've got a website that use a front controller that redirect traffic to certain files so I can employ SEO friendly URLs however there are some static pages on the site which I don't want traffic directed away from:

I currently have the following .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.exmple.com/$1 [L,R=301]
ErrorDocument  404  /controller.php

which seems to work fine:

  • All traffic is diverted to www.example.com;
  • And any web page that isn't found is directed to controller.php to handle;
  • Anything that actually exists such as www.example.com/about_us.php still works;

The problems is that it still reports a 404 error even though the page is still sent and displayed correctly - it doesn't look any different to the end user but its messing up my SEO with Google as the Google bot sees the 404 and assumes there's nothing else there.

Is there any way I can simply redirect all traffic apart from a list of certain pages or is there a more elegant solution?

Any help, thoughts, comments, etc. would be most welcome

解决方案

RewriteEngine On
ErrorDocument  404  /controller.php

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT]

You should route through index.php... otherwise line below should work instead of upper one.

RewriteRule .* $0 [PT]

这篇关于mod_rewrite的重定向如果没有找到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆