.htaccess url-rewrite 如果文件不存在 [英] .htaccess url-rewrite if file not exists

查看:37
本文介绍了.htaccess url-rewrite 如果文件不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为一个网站做一个小把戏!思路是:

I must do a little trick for a site! The idea is:

  • 如果存在所需 url 的文件,那么我会转到该 url,什么也不做;
  • 如果所需 url 的文件不存在,我必须转到 file.php 并执行某些操作,但不要更改 url!

示例:

www.mysite.com/page1.htm -> 存在 -> 转到文件 page1.htm

www.mysite.com/page1.htm -> exists -> go to file page1.htm

www.mysite.com/page2.htm -> 不存在 -> 转到文件 default.php 但使用 url "www.mysite.com/page2.htm"

www.mysite.com/page2.htm -> NOT exists -> go to file default.php but with url "www.mysite.com/page2.htm"

可以通过 .htaccess 来完成这一切吗?

It's possible to do this all by .htaccess?

推荐答案

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /default.php [L]

这篇关于.htaccess url-rewrite 如果文件不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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