Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache mod_rewrite从特定文件中删除.php并阻止访问原始文件_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache mod_rewrite从特定文件中删除.php并阻止访问原始文件

Apache mod_rewrite从特定文件中删除.php并阻止访问原始文件,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我想改变一下: www.foo.com/bar.php 致: 之后,禁止直接访问/bar.php,但允许/bar: www.foo.com/bar.php 404 Not Found 我希望访问bar.php时出现404错误。 基本上,我希望它看起来像“bar”是一个目录 这可能吗 我目前的代码是: RewriteEngine On RewriteRule ^bar/?$ bar.php [NC] 您可以使用以下选项: RewriteEngine on #prevent direct

我想改变一下:

www.foo.com/bar.php
致:

之后,禁止直接访问/bar.php,但允许/bar:

www.foo.com/bar.php    404 Not Found
我希望访问bar.php时出现404错误。
基本上,我希望它看起来像“bar”是一个目录

这可能吗

我目前的代码是:

RewriteEngine On
RewriteRule ^bar/?$ bar.php [NC]
您可以使用以下选项:

RewriteEngine on
#prevent direct access to /bar.php
#return a 404 error if /bar.php is direct accessed
RewriteCond %{THE_REQUEST} /bar\.php [NC]
RewriteRule ^ - [R=404,L]
#rewrite /bar to /bar.php
#this will internally forward http://example.com/bar to http://example.com/bar.php
RewriteRule ^bar$ /bar.php [L]

您的“当前代码”似乎已经完成了主要部分-有什么问题吗?您的应用程序中的URL可能已更改为
/bar
?谢谢,它可以正常工作!只是一个问题,[L]标志的作用是什么?NC标志似乎起作用了aswell@SveaNils
RewriteEngine on
#prevent direct access to /bar.php
#return a 404 error if /bar.php is direct accessed
RewriteCond %{THE_REQUEST} /bar\.php [NC]
RewriteRule ^ - [R=404,L]
#rewrite /bar to /bar.php
#this will internally forward http://example.com/bar to http://example.com/bar.php
RewriteRule ^bar$ /bar.php [L]