Cri*_*sty 6 regex apache .htaccess mod-rewrite redirect
标题解释了基础,现在,问题出现了:
我有很多文件看起来像这样:
<?php include 'mynavbar.php';
include 'myheader.php';
include 'myfirstline.php';
include 'mybuttons.php';
include 'myadvert.php';
include 'myimg.php';?>
Run Code Online (Sandbox Code Playgroud)
我无法编辑所有文件并删除.php.我怎么能不显示.php在地址栏,但仍然可以使用能够包括网页.php的结局
anu*_*ava 11
以下代码应该在.htaccess文件中为您隐藏.php扩展名:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# to make `/path/index.php` to /path/
RewriteCond %{THE_REQUEST} ^GET\s(.*/)index\.php [NC]
RewriteRule . %1 [NE,R=301,L]
RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Run Code Online (Sandbox Code Playgroud)
还记得这些规则对你的php包含没有任何影响,例如: include 'myheader.php';
这是因为那些包含是由PHP本身处理的,而不是通过Apache.