Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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中mod_重写的问题_Php_Mod Rewrite - Fatal编程技术网

Php apache中mod_重写的问题

Php apache中mod_重写的问题,php,mod-rewrite,Php,Mod Rewrite,这其实不是mod_重写的问题,而是我的问题。我很确定我的错误很愚蠢,但我无法解决它。 我在Mac OS X Lion上安装了一个非常简单的XAMPP,使用一个简单的index.php脚本,它什么也不做。我只是想学习如何在php中使用友好的url,所以,如果我收到一个这种格式的url http://localhost/project/controller_name/action_name/id 那么,如果我收到这个 http://localhost/project/user/delete/7

这其实不是mod_重写的问题,而是我的问题。我很确定我的错误很愚蠢,但我无法解决它。 我在Mac OS X Lion上安装了一个非常简单的XAMPP,使用一个简单的index.php脚本,它什么也不做。我只是想学习如何在php中使用友好的url,所以,如果我收到一个这种格式的url

http://localhost/project/controller_name/action_name/id
那么,如果我收到这个

http://localhost/project/user/delete/7
可以在内部使用类似的东西

http://localhost/project/index.php?controller=user&action=delete&id=7
我使用此内容在项目文件夹上创建了一个.httaces

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /aletta/index.php?controller=$1&action=$2&id=$3 [L]
我检查了是否启用了模式_重写,并且它是。但是不起作用。我打字
http://localhost/project/user/delete/7
页面显示“找不到对象!”


任何帮助都将非常感谢

尝试此操作,
.htaccess
文件放在根目录中:

Options +FollowSymLinks -MultiViews

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    # set project dir to RewriteBase
    RewriteBase /aletta/
    RewriteRule ^([0-9a-zA-Z\-]+?)/([0-9a-zA-Z\-]+?)?/([0-9a-zA-Z\-]+?)?$ index.php?controller=$1&action=$2&id=$3

</IfModule>
如果要将/project/$alphanum1/$alphanum2/$numeric重新映射到/project/index.php?controller=$alphanum1&action=$alphanum2&id=$numeric,则可以尝试以下配置指令:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^project/([a-z0-9-_]+)/([a-z0-9-_]+)/([0-9]+)/?$ /project/index.php?controller=$1&action=$2&id=$3 [NC]

您的文档根目录是什么?您将.htaccess放在何处?
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^project/([a-z0-9-_]+)/([a-z0-9-_]+)/([0-9]+)/?$ /project/index.php?controller=$1&action=$2&id=$3 [NC]