Php 重写文件扩展名,但拒绝直接访问文件
我正在寻找通过.htaccess隐藏文件扩展名并拒绝直接访问的方法。让我们考虑如下:Php 重写文件扩展名,但拒绝直接访问文件,php,security,rewrite,hide,Php,Security,Rewrite,Hide,我正在寻找通过.htaccess隐藏文件扩展名并拒绝直接访问的方法。让我们考虑如下: http://www.xyz.zyx/index.php 转换为 http://www.xyz.zyx/index OR http://www.xyz.zyx/ 到现在为止一切都很好。我接下来要做的是在用户尝试直接访问时阻塞或重定向。例如,如果用户在URL栏中键入以下内容(扩展名)、阻止或重定向: http://www.xyz.zyx/index.php 我检查了其他问题的其他答案,但似乎恰恰相反 提前
http://www.xyz.zyx/index.php
转换为
http://www.xyz.zyx/index OR http://www.xyz.zyx/
到现在为止一切都很好。我接下来要做的是在用户尝试直接访问时阻塞或重定向。例如,如果用户在URL栏中键入以下内容(扩展名)、阻止或重定向:
http://www.xyz.zyx/index.php
我检查了其他问题的其他答案,但似乎恰恰相反
提前感谢您帮助我这样的新手。虽然有人可能会质疑这样一件事的有用性,但它是可行的,因此下面介绍如何在
中使用mod_rewrite
来访问:
RewriteEngine On
# Sets your index script
RewriteRule ^$ index.php [L]
# Condition prevents redirect loops (when script is not found)
RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteCond %{REQUEST_FILENAME} !-f
# Stop here if the file is not found after a redirect
RewriteRule ^(.*)$ notfound.php [L]
# Condition prevents redirect loops (when script is found)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Forbid access directly to PHP files
RewriteRule ^.*?\.php$ forbidden [F,L]
# Make sure the filename does not actually exist (images, etc.)
RewriteCond %{REQUEST_FILENAME} !-f
# Append the .php extension to the URI
RewriteRule ^(.*)$ $1.php [L]
可能的副本,