【问题标题】:Single entry point by .htaccess show 500 internal error.htaccess 的单一入口点显示 500 内部错误
【发布时间】:2016-01-11 19:06:08
【问题描述】:

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

我的应用程序树:

本地主机/mvc

我。控制器

二。型号

三。意见

四。网络根

一个。索引.php 湾。 .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:

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

【问题讨论】:

  • 500 错误只是一般的“有问题”类型的错误。这可能意味着一千件事,但是规则可能是您的问题。检查您的 apache 错误日志以获取有关问题所在的更多详细信息。它默认为/var/log/Apache2/error.log,并且会有错误的实际原因。
  • 我试过了,但还是不行。 500 内部错误。请帮助我长时间忍受它。
  • 日志抛出以下错误:[Wed Oct 14 03:18:53.569210 2015] [core:alert] [pid 10028] [client ::1:37363] /var/www/html/ mvc/.htaccess:
  • 有一个空格,我已将其删除,然后显示以下错误:/var/www/html/mvc/webroot/.htaccess: RewriteRule: bad flag delimiters
  • 嗨,太好了。有用。请附上答案。我会接受它。非常感谢

标签: php regex apache .htaccess ubuntu


【解决方案1】:

这行是问题所在:

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>

【讨论】:

    猜你喜欢
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 2021-11-29
    • 2016-09-22
    • 2017-04-05
    • 1970-01-01
    相关资源
    最近更新 更多