单一入口点.htaccess显示500内部错误


Single entry point by .htaccess show 500 internal error

我试图为我的自定义php mvc应用程序创建一个单一的入口点。我使用apache2作为php服务器在我的ubuntu 14.04操作系统。

我的应用树:

localhost/mvc

。控制器

二世。模型

iii。视图

第四。webroot

。index . phpb。htaccess

v . htaccess

我的根目录。htaccess代码:

<IfModule mod_rewrite.c >
    RewriteEngine on
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]
</IfModule>

和webroot/。Htaccess代码:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [PT, L]
</IfModule>

但它显示如下500状态码:

内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求。

这一行就是问题所在:

RewriteRule ^(.*)$ index.php [PT, L]

由于PT,后面有一个空格。mod_rewrite语法非常严格,它不允许任何地方出现未转义的空格。

您的webroot/.htaccess可以是:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [PT,L]
</IfModule>