由网友(誰萆嶶ㄋ承諾)分享简介:有这样的code在htaccess文件来隐藏每个文件的最后一个PHP扩展have this code in a htaccess file to hide the final php extension of each fileRewriteEngine onRewriteCond %{REQUEST_FILEN...
有这样的code在htaccess文件来隐藏每个文件的最后一个PHP扩展
have this code in a htaccess file to hide the final php extension of each file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
但现在我想重定向到另一个页面,如果用户试图完成扩展。
but now i want to redirect to another page if the user try to complete the extension.
我想上面的脚本后,这条线,但我得到一个500内部错误
i tried this line after the script above but i get a 500 internal error
RewriteRule .php$ - [R=404]
谢谢!
推荐答案
有你的重写规则是这样的:
Have your rewrite rules like this:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !^myvar=0
RewriteCond %{REQUEST_URI} !..*$
RewriteRule ^(.*)$ /$1.php?myvar=0 [QSA,L]
# but don't allow example.com/foo.php
RewriteCond %{QUERY_STRING} !^myvar=0$
RewriteRule .php$ - [R=404,L]
基本上第一条规则是附加在URL伪查询参数 MYVAR = 0
二是检查其非presence踢,因此,如果用户类型/abc.php那么它被阻止,但如果只/ ABC则在内部重定向到/abc.php。
Basically first rule is appending a dummy query parameter myvar=0
in the URL and second is checking its non-presence to kick in, hence if user types /abc.php then it is blocked but if just /abc then it is internally redirected to /abc.php.
相关推荐
最新文章