Apache 内部服务器错误-HTACCESS文件

Apache 内部服务器错误-HTACCESS文件,apache,.htaccess,wamp,Apache,.htaccess,Wamp,我有以下资料: C:\wamp\www\MyProject 目录结构如下所示: MyProject folder1 folder2 index.php .htaccess 和htaccess文件包含: # Turn on mod_rewrite handling RewriteEngine On # Allows for three wildcards: page, action and id RewriteRule (.*?)/(.*?)/(.*?)$ index.

我有以下资料:

C:\wamp\www\MyProject
目录结构如下所示:

MyProject
   folder1
   folder2
   index.php
   .htaccess
htaccess
文件包含:

# Turn on mod_rewrite handling
RewriteEngine On
# Allows for three wildcards: page, action and id
RewriteRule (.*?)/(.*?)/(.*?)$
index.php?page=$1&action=$2&id=$3
每当我试图访问http:\\127.0.0.1/MyProject/testpage/testaction/testid时,我都会收到以下错误:


我在这里做错了什么?

您有语法错误。重写规则需要在单行中

试试这个规则:

RewriteEngine On
RewriteBase /MyProject/

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Allows for one wildcard: page
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]

# Allows for two wildcards: page, action
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&action=$2 [L,QSA]

# Allows for three wildcards: page, action and id
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?page=$1&action=$2&id=$3 [L,QSA]

和往常一样,当重写出现问题时(您怀疑),打开重写日志!查看优秀的apache文档,查看mod_rewrite的文档,找到命令“RewriteLog”和“RewriteLogLevel”。没有调试就像在黑暗中摸索。为什么不用电灯开关?好的。我已经把它放在一条线上了,现在可以用了。但是每当我尝试
http://127.0.0.1/MyProject/asdf/jkl
它表示在该服务器上找不到请求的URL。我的
index.php
文件中的内容只是一个
vardump($\u GET)
如果.htaccess是
/MyProject/
,那么请查看更新的代码。它将与
http://127.0.0.1/MyProject/asdf/jkl/xyz
(在
/MyProject/
之后有3个斜杠)它可以工作,但前提是我总是提供
页面
操作
id
。如果我只想强制设置
页面
该怎么办?很抱歉,它现在根本不起作用。我可以打开
http://127.0.0.1/MyProject
RewriteEngine On
RewriteBase /MyProject/

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Allows for one wildcard: page
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]

# Allows for two wildcards: page, action
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&action=$2 [L,QSA]

# Allows for three wildcards: page, action and id
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?page=$1&action=$2&id=$3 [L,QSA]