没有根据请求的URL找到类

时间:2017-08-13 07:08:29

标签: php .htaccess url-routing

这是我在mvc项目中的.htaccess

+-----------+---------------+-------+--------+
| Name      | Location      | Sales | Profit |
+-----------+---------------+-------+--------+
| Company A | Houston       | 100   | 50     |
+-----------+---------------+-------+--------+
| Company B | San Francisco | 500   | 200    |
+-----------+---------------+-------+--------+
| Company C | New York      | 200   | null   |
+-----------+---------------+-------+--------+
| Company C | San Francisco | null  | 150    |
+-----------+---------------+-------+--------+

这是我在控制器文件夹中的简单类

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

这是我的索引页面,我想在url中的控制器部分是索引时打印控制器部分并运行类。但它错了:

class index {
    function __construct()
    {
        echo "this page is index";
    }
}

Undefined index: url    

我的代码:

require(controllers/.php): failed to open stream: No such file or directory

1 个答案:

答案 0 :(得分:0)

  • 不要忘记为重定向(RewriteBase)重写“基础”。
  • 删除第RewriteCond %{REQUEST_FILENAME} !-l行。是-l 选项甚至存在?

以下是文档根“Publics”的示例,其中文件“index.php”驻留在:

<Directory "[your-absolute-path-to]/Publics">
    Options FollowSymLinks

    # Uncomment if you want to only allow localhost.
    # Allow from 127.0.0.1

    # Activate rewriting engine.
    RewriteEngine On

    # Allow pin-pointing to "index.php" using RewriteRule.
    RewriteBase /

    # Rewrite url only if no physical folder name is given in url.
    RewriteCond %{REQUEST_FILENAME} !-d

    # Rewrite url only if no physical file name is given in url.
    RewriteCond %{REQUEST_FILENAME} !-f

    # Take the common url and parse it through "index.php" as a query string, e.g as "url=[...]".
    # ----------------------------------------------------------------------------------
    # SEE: RewriteRule Flags >> https://httpd.apache.org/docs/current/rewrite/flags.html
    # ----------------------------------------------------------------------------------
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L,B]
</Directory>
相关问题