我使用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]