的.htaccess重写所有PHP文件 [英] .htaccess rewrite all php files
问题描述
我已经写了我的规则来显示所有我的PHP文件等从work.php工作 这样既可以显示。我.hataccess是如下
I have wrote my rules to display all my php files etc work from work.php so both can show. My .hataccess is as follow
Options +FollowSymlinks
RewriteEngine on
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
这是我有,我不知道。htaccess可以帮助解决这个问题是这样的,我所有的code具有的.php附加到底。 有没有一种简单的方法来处理呢?部队的.htaccess更改所有的.php不了了之? 我是pretty的肯定是不可能的,生病需要做一个code审查和手动更改它们。
the issue that i am having and i am not sure that htaccess can help with this is that, all of my code has .php appended in the end. Is there an easy way to handle this ? Force .htaccess to change all the .php to nothing ? I am pretty sure that is not possible and ill need to do a code review and change them all manually.
我希望我说的话了明确的。
I hope that i said it out clear.
感谢名单
推荐答案
下面是code,你可以用它来隐藏PHP扩展。将其放在.htaccess文件在$ DOCUMENT_ROOT目录:
Here is the code that you can use to hide .php extension. Put it inside .htaccess file in your $DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
这篇关于的.htaccess重写所有PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!