在Yii中制作漂亮的网址

时间:2013-11-27 11:39:51

标签: .htaccess url yii

我重写了很多tuttorials,但都引发了我同样的错误 - 错误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记录了几条记录:

  

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

1 个答案:

答案 0 :(得分: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 ...

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

至于“此处不允许的选项”错误,请参阅this answer