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
如何使url在没有任何重写条件的情况下重写apache?_Apache_Mod Rewrite - Fatal编程技术网

如何使url在没有任何重写条件的情况下重写apache?

如何使url在没有任何重写条件的情况下重写apache?,apache,mod-rewrite,Apache,Mod Rewrite,对不起,但是我不太了解url重写 我想从以下位置重写我的url: http://localhost/controller/index.php/user/edit 到 http://localhost/controller/user/edit 我可以用这个。htaccess: RewriteEngine On RewriteBase /controller/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-

对不起,但是我不太了解url重写

我想从以下位置重写我的url:
http://localhost/controller/index.php/user/edit


http://localhost/controller/user/edit

我可以用这个。htaccess:

RewriteEngine On
RewriteBase /controller/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [PT,L]
但是,如果
controller/user/edit.php
我希望我的
controller/xxx
下的每个请求都被重写为
controller/index.php/xxx
,无论文件是否存在

我已经删除了重写条件,所以我当前的一个是这样的:

RewriteEngine On
RewriteBase /controller/
RewriteRule ^(.*)$ index.php/$1 [PT,L]

但是,它显示了
内部服务错误

有很多事情对我来说没有意义。主要是,您的问题是希望将包含index.php的URL重写为不包含index.php的URL,但您的重写规则(您说在某些情况下有效)的作用正好相反,它会将index.php预挂在请求上

如果您可以访问apache错误和访问日志,您可能会看到关于错误发生的确切时间点是否有更多信息——是在处理.htaccess文件时,还是在php程序中

我将假设这里的目标是采用像/controller/user/edit这样的“漂亮”URL,并让index.php程序实际处理路径的/user/edit部分

如果是这样,我想您可能需要将RewriteBase设置为/,并将.htaccess更改为

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ controller/index.php/$1 [PT,L]
RewriteBase/
指令说明所有请求都与服务器的
DOCUMENT\u ROOT
设置相关。对重写规则的更改指示所有请求转到目录
controller
和文件
index.php
,随后追加原始请求路径

(注意:在本例中,我认为您不想使用
PT
标志,最好是将.php作为
index\.php
的regex运算符转义,但我认为这两种形式都与此处的问题无关)

不清楚您是否希望在1美元之前使用/。如果您的PHP程序(index.PHP)正在被调用,并且知道如何处理它,那么这很好,但有点不寻常,并且可能会在PHP程序中出现多个/

但你真的想这么做吗?
RewriteCond%{REQUEST\u FILENAME}的典型用法-f
用于处理静态的图像文件和css或javascript文件等不需要控制器处理的情况<代码>重写cond%{REQUEST_FILENAME}-d
取决于您的系统(但其目的是确保请求不针对目录)

无论如何,我建议的基本更改可能会有所帮助,但如果没有,也许您可以澄清您的意图,并提供一些实际的URL和index.php内部的外观