【问题标题】:Making nice Urls in Yii在 Yii 中制作漂亮的 Url
【发布时间】:2013-12-13 00:52:31
【问题描述】:

我刷了很多教程,但都导致我出现相同的错误 - 错误 500 - 服务器过载或 CGI 脚本中存在错误。

我在 Windows 上使用 xampp 并像这样配置 httpd.conf

<Directory />
  Options FollowSymLinks
  AllowOverride All
  Order deny,allow
  Allow from all
</Directory>

在 yii main.php 中修改

    'urlManager'=>array(
        'urlFormat'=>'path',
                    'showScriptName'=>false,
                    'caseSensitive'=>false, 
        'rules'=>array(  
                            '' => 'site/index',     

            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
    ),

并在根文件夹(受保护文件夹的同一级别)中添加 .htaccess

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteBase /tests/

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

但无论我在 .htaccess 中写什么,我都会收到此错误。当我全部注释掉时,yii 的链接生成正常(没有 index.php),但是由于服务器配置错误,我有 404 错误。

编辑:

还有error.log最后几条记录:

[2013 年 11 月 27 日星期三 11:32:31.100063] [core:alert] [pid 9520:tid 1572] [client ::1:58620] C:/Users/kristineg/xamps/htdocs/xampp/tests/。 htaccess:此处不允许的选项 [2013 年 11 月 27 日星期三 11:32:31.372163] [core:alert] [pid 9520:tid 1572] [client ::1:58621] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许 [2013 年 11 月 27 日星期三 11:32:34.674379] [core:alert] [pid 9520:tid 1572] [client ::1:58622] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许 [2013 年 11 月 27 日星期三 11:32:36.587084] [core:alert] [pid 9520:tid 1572] [client ::1:58623] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许 [2013 年 11 月 27 日星期三 11:32:54.899832] [core:alert] [pid 9520:tid 1572] [client ::1:58624] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许 [2013 年 11 月 27 日星期三 11:54:14.056192] [core:alert] [pid 9520:tid 1572] [client ::1:59297] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许 [2013 年 11 月 27 日星期三 11:54:14.687425] [core:alert] [pid 9520:tid 1572] [client ::1:59298] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许 [Wed Nov 27 15:53:27.459885 2013] [ssl:warn] [pid 11320:tid 308] AH01909:为 www.example.com:443 配置的 RSA 证书不包含与服务器名称匹配的 ID [2013 年 11 月 27 日星期三 15:53:27.525911] [core:warn] [pid 11320:tid 308] AH00098: pid 文件 C:/Users/kristineg/xamps/apache/logs/httpd.pid 被覆盖 -- 以前的不干净关闭阿帕奇运行? [Wed Nov 27 15:53:27.588934 2013] [ssl:warn] [pid 11320:tid 308] AH01909:为 www.example.com:443 配置的 RSA 证书不包含与服务器名称匹配的 ID [2013 年 11 月 27 日星期三 15:53:27.625947] [mpm_winnt:notice] [pid 11320:tid 308] AH00455: Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.1 已配置 -- 恢复正常操作 [2013 年 11 月 27 日星期三 15:53:27.625947] [mpm_winnt:notice] [pid 11320:tid 308] AH00456:服务器构建时间:2013 年 2 月 23 日 12:42:00 [2013 年 11 月 27 日星期三 15:53:27.625947] [core:notice] [pid 11320:tid 308] AH00094:命令行:'c:\users\kristineg\xamps\apache\bin\httpd.exe -d C:/用户/kristineg/xamps/apache' [2013 年 11 月 27 日星期三 15:53:27.627948] [mpm_winnt:notice] [pid 11320:tid 308] AH00418: Parent: Created child process 4472 [2013 年 11 月 27 日星期三 15:53:27.998083] [ssl:warn] [pid 4472:tid 336] AH01909:为 www.example.com:443 配置的 RSA 证书不包含与服务器名称匹配的 ID [Wed Nov 27 15:53:28.143138 2013] [ssl:warn] [pid 4472:tid 336] AH01909:为 www.example.com:443 配置的 RSA 证书不包含与服务器名称匹配的 ID [2013 年 11 月 27 日星期三 15:53:28.186154] [mpm_winnt:notice] [pid 4472:tid 336] AH00354:子级:启动 150 个工作线程。 [2013 年 11 月 27 日星期三 15:53:38.827074] [core:alert] [pid 4472:tid 1640] [client ::1:61797] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许 [2013 年 11 月 27 日星期三 15:53:39.614364] [core:alert] [pid 4472:tid 1652] [client ::1:61796] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许 [2013 年 11 月 27 日星期三 15:53:39.958491] [core:alert] [pid 4472:tid 1640] [client ::1:61798] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许 [2013 年 11 月 27 日星期三 15:53:40.295616] [core:alert] [pid 4472:tid 1652] [client ::1:61799] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许 [2013 年 11 月 27 日星期三 16:32:32.894114] [core:alert] [pid 4472:tid 1640] [client ::1:62407] C:/Users/kristineg/xamps/htdocs/xampp/tests/.htaccess: 选项这里不允许

【问题讨论】:

    标签: .htaccess url yii


    【解决方案1】:

    我认为您的服务器主配置中没有加载mode_rewrite 模块。对于初学者,请修改您的 .htaccess,使其看起来像这样:

    IndexIgnore */*
    
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteBase /tests/
    
        # if a directory or a file exists, use it directly
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
    
        # otherwise forward it to index.php
        RewriteRule . index.php
    </IfModule>
    

    如果情况有所好转(即没有 500 错误),请查看您的主要 httpd.conf 并查找以这样开头的行:

    #LoadModule rewrite_module ...
    

    通过删除前导 # 取消注释该行并重新启动服务器进程。

    至于“Options not allowed here”错误,见this answer

    【讨论】:

    • 取消注释该行,重新启动服务器并更改.htaccess,但同样的错误:(
    • 那肯定还有什么问题。你能检查错误日志吗?应该在apache\logs\error.log
    • 刚刚添加了最后的日志记录。嗯,“.htaccess:此处不允许的选项”。它位于根文件夹中。
    • 我已经更新了我的答案以反映这一点。看起来您需要将该选项节拉到您的主配置中。
    猜你喜欢
    • 2019-02-08
    • 1970-01-01
    • 2021-01-29
    • 2014-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多