如何使 .htaccess 在当前目录而不是子目录上工作? [英] How do I make .htaccess work on the current directory and not subdirectories?

查看:36
本文介绍了如何使 .htaccess 在当前目录而不是子目录上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 mod rewrite 间接访问我网站根目录中的 PHP 文件.目前,我有这样的事情,

I'm using mod rewrite to access my PHP files in the root directory of my website indirectly. Currently, I have something like this,

RewriteRule ^(blog|about|page3|etc)$ /$1.php [L]

但我想用的是

RewriteRule ^(.*)$ /$1.php [L]

这样每当我想向我的网站添加新页面时就不必更新我的 .htaccess 文件.然而,问题在于它也会影响我的子目录.这使得 CSS、javascript、图像无法访问,因为它重定向到/dir/example.png.php".

So that I wouldn't have to update my .htaccess file whenever I wanna add a new page to my website. The problem with this however is that it affects my subdirectories too. Which makes CSS, javascript, images unaccessable because it redirects to "/dir/example.png.php".

那么这里最好的解决方案是什么?

So what is the best solution here?

推荐答案

试试这个规则:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule .* $0.php [L]

这篇关于如何使 .htaccess 在当前目录而不是子目录上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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