Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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参数的Apache重写问题_Php_Apache_.htaccess - Fatal编程技术网

使用php参数的Apache重写问题

使用php参数的Apache重写问题,php,apache,.htaccess,Php,Apache,.htaccess,我想以以下格式访问我的页面:mysite.com/parameter而不是mysite.com/index.php?param=parameter。我使用了httpd.conf文件,我管理的最好的文件是mysite.com/dir/parameter 我的意见如下: Options Indexes MultiViews Includes ExecCGI Options FollowSymLinks AllowOverride All

我想以以下格式访问我的页面:mysite.com/parameter而不是mysite.com/index.php?param=parameter。我使用了httpd.conf文件,我管理的最好的文件是mysite.com/dir/parameter

我的意见如下:

        Options Indexes MultiViews Includes ExecCGI
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        RewriteEngine On
        RewriteRule /(.*)$ index.php?hash=$1 [NC] 
我怎样才能摆脱过多的目录

改为:

           RewriteEngine On
           RewriteRule ^(.*) index.php?hash=$1 [NC]
尝试打开页面时导致以下错误

禁止的


您没有访问此服务器上的/Šw^Æi的权限。

如果您在
.htaccess
样式文件中有此配置,请删除前导斜杠(
/
),并防止将请求重写到实际存在的内容:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?hash=$1 [L,NC]
如果需要移交其他参数,您可能还需要添加一个附加的
QSA
标志


如果您将这种配置放在真正的服务器配置中(如果您有访问权限,这是更好的选择),那么您当前的设置应该很好
.htaccess
样式的文件会大大降低服务器的速度,它们极易出错,而且很难调试

首先,您必须确保不会通过将url重写为与重写规则再次匹配的内容来创建无限循环,这可能是导致目录isse的原因:

RewriteRule /(.*) index.php?hash=$1 [NC,L]
其次,检查文件是否存在可能很有帮助,例如,如果您想提供图像或robots.txt,如果您检查index.php是否存在,这也可能解决您的循环问题:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /(.*) index.php?hash=$1 [NC,L]

对现有文件的请求将取决于本地文件的正常处理。

该配置是在
.htaccess
样式的文件(如问题标签所示)中还是在服务器配置中?谢谢,这很有帮助。案件结案!谢谢你的反馈!很荣幸!