Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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 mod_rewrite未检测到项目的参数_Php_.htaccess_Mod Rewrite_Wamp - Fatal编程技术网

Php htaccess mod_rewrite未检测到项目的参数

Php htaccess mod_rewrite未检测到项目的参数,php,.htaccess,mod-rewrite,wamp,Php,.htaccess,Mod Rewrite,Wamp,我启动了一个基于的php项目,并在Google上搜索如何设置我的WAMP服务器,以启用URL重写 我正在运行最新版本的WAMP 1) 在httpd.conf 2) 在httpd vhosts.conf上,我添加了一个虚拟主机 <VirtualHost *:80> ServerName phpmvc.test ServerAlias *.phpmvc.test VirtualDocumentRoot "C:\wamp\www\phpmvc" ErrorLog "logs\errors.

我启动了一个基于的php项目,并在Google上搜索如何设置我的
WAMP服务器
,以启用
URL
重写

我正在运行最新版本的WAMP

1) 在
httpd.conf

2) 在httpd vhosts.conf上,我添加了一个虚拟主机

<VirtualHost *:80>
ServerName phpmvc.test
ServerAlias *.phpmvc.test
VirtualDocumentRoot "C:\wamp\www\phpmvc"
ErrorLog "logs\errors.log"
<directory "C:\wamp\www\phpmvc">
    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from all
</directory>
设置文件后,我重新启动了Apache,当我转到
phpmvc.test
时,它工作正常,但当我尝试
phpmvc.test/test
时,它显示一个错误,表明在此服务器上找不到请求的URL

编辑:我尝试了
RewriteRule^(.*)$index.php?url=$1[QSA,L]
,但它显示了相同的错误 编辑2:我试过编辑:我试过拉希尔·瓦齐尔的建议,但仍然不起作用

我有一个控制器文件
IndexController.class.php
,如果我用这个URL访问它就会工作:
phpmvc.test?URL=index
,但是如果我尝试
phpmvc.test/index
,它会说服务器上找不到
index

<?php

class IndexController {

    public static function index() {

        echo "Index controller";

    }
}

这是因为Apache认为
/test
是您试图访问的文件或目录,而这些文件或目录可能不存在

您需要应用大多数框架使用的两个著名条件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

它告诉Apache重写模块,除非请求uri中的文件或目录存在,否则应用重写规则,否则呈现文件或目录的内容。

通过检查$\u GET和$\u服务器变量中的内容进行调试

print_r($_GET);
print_r($_SERVER);
比较['url']索引值的差异。
此外,它可能取决于您的子文件夹深度,如/index之前的URL所示。

您的重写规则取决于传入路径的尾随斜杠。
/我添加了您说的行,但错误仍然存在:/i添加了您告诉我的信息
print_r($_GET);
print_r($_SERVER);