我如何在当前目录下,而不是子目录的.htaccess工作? [英] How do I make .htaccess work on the current directory and not subdirectories?
本文介绍了我如何在当前目录下,而不是子目录的.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]
但我想用的是
But what I would like to use is
RewriteRule ^(.*)$ /$1.php [L]
所以,我不会有每当我想添加一个新的页面,我的网站更新我的.htaccess文件。这样做的问题则在于,它会影响我的子目录了。这使得CSS,JavaScript,图片unaccessable因为它重定向到/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屋!
查看全文