Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.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
Php 如何为现有文件和文件夹设置.htaccess_Php_Apache_.htaccess - Fatal编程技术网

Php 如何为现有文件和文件夹设置.htaccess

Php 如何为现有文件和文件夹设置.htaccess,php,apache,.htaccess,Php,Apache,.htaccess,有人能帮我吗 我的使用案例是,如果目录中有index.php,则加载index.php,否则设置rewriteRule来调用probled.php 我做了一点,但还没有成功。我的服务器上的htaccess代码是- <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteCon

有人能帮我吗

我的使用案例是,如果目录中有index.php,则加载index.php,否则设置rewriteRule来调用probled.php

我做了一点,但还没有成功。我的服务器上的htaccess代码是-

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond ^(.*)$/index.php !-d

RewriteCond %{REQUEST_URI} (.*)/$
RewriteRule ^(.*)$ forbidden.php?handle=$1

</IfModule>

重新启动发动机
重写基/
重写cond%{SCRIPT_FILENAME}-F
重写cond%{SCRIPT_FILENAME}-D
重写cond^(.*)$/index.php-D
RewriteCond%{REQUEST_URI}(.*)/$
RewriteRule^(.*)$forbidden.php?句柄=$1

我认为有一种更简单的方法来做你想做的事。不需要重写,只需定义哪个页面作为入口页面即可。在.htaccess文件中,您可以定义:

DirectoryIndex index.php
ErrorDocument 404 /forbidden.html
现在,如果有人调用您的目录,页面将显示


如果index.html文件不存在,服务器将返回错误,因此您可以定义适当的错误页面。使用前导/,您可以在根目录中定义单个错误页,而不使用/it将在相对目录中查找http://www.example.com/user/forbidden.php.

非常感谢。我用另一种方法做了,但这是一种更简单的方法,因此,我将更改我的代码。