为什么以下apache htaccess代码不会返回我的页面?

时间:2012-05-31 06:39:18

标签: apache .htaccess

我已经请求了一个网址“http:// mydomain / testscripts / php_Env”

我的testscripts文件夹中有一个文件php_Env.php ..

我的htaccess如下

RewriteEngine On    # Turn on the rewriting engine
RewriteCond %{REQUEST_FILENAME} !-f    # Existing File
RewriteCond %{REQUEST_FILENAME} !-d    # Existing Directory
RewriteRule    ^(php_([a-zA-Z_]+))$  $1.php   [NC,L]

运行时,浏览器会返回

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log

我想要做的是如果请求文件不是目录而不是文件,请求文件。我在htaccess哪里出错?

1 个答案:

答案 0 :(得分:1)

尝试没有多余的空格和评论:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(php_([a-zA-Z_]+))$ $1.php [NC,L]

如果有效,您可以添加注释(可能只在规则中的最后一个字符和#符号之间留一个空格。)