我是php和Yii的新手,这可能是一个非常愚蠢的问题。我在Mac OS X上使用Yii框架来开发Web应用程序。我正在处理的代码库是在Windows机器上安装的,在Windows操作系统上运行得非常好。但是,当我尝试在Mac OS X上运行它时,我收到404未找到错误。在main.php配置文件中,url路由似乎存在问题。
我的网址管理员有以下代码
'urlManager'=>array(
'showScriptName'=>false,
'caseSensitive'=>true,
'urlFormat'=>'path',
'rules'=>array(
'' => 'home',
'learn-more' => 'home/learn_more',
'cpi' => 'cpi/index',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<controller:\[\w\-]+>/<action:\[\w\-]+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\[\w\-]+>/<action:\[\w\-]+>/<code:\w+>'=>'<controller>/<action>',
'<controller:\[\w\-]+>/<action:\[\w\-]+>'=>'<controller>/<action>',
),
),
我的文件夹结构如下所示
> protected
> components
> config
> controllers
> views
> about
> careers
> contact
> cpi
> devadmin
> error
> home
> info
> layouts
项目文件夹中的.htaccess文件包含以下代码行
RewriteEngine on
# 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
我的主页http://mysite.com必须映射到/ home / index(即HomeController中的索引操作),这非常有效。 “views”下的每个其他文件夹都有一个index.php文件。我需要将http://mysite.com/devadmin类型的URL映射到/ devadmin / index。在Windows操作系统下运行时,现有规则可以正常工作,但在Mac OS上出现错误。我想知道我的网址管理器中是否有任何特定于Windows的代码。如果有人能建议我解决这个问题,我会很高兴。
答案 0 :(得分:0)
尝试做这样的事情:
'urlManager' => array(
'showScriptName' => false,
'caseSensitive' => true,
'urlFormat' => 'path',
'rules' => array(
'' => 'home',
'learn-more' => 'home/learn_more',
'cpi' => 'cpi/index',
'<controller>/<action>/<id:\d+>' => '<controller>/<action>',
'<controller>/<action>/<code:\w+>' => '<controller>/<action>',
),
),
我不知道你的要求。如果它对您没有帮助,请尝试在您的问题中添加更多详细信息。
答案 1 :(得分:0)
如果您希望它最终适用于domain.com/devadmin
而不是/index
,则需要向您的网址管理员添加其他规则:
'' => 'home',
'learn-more' => 'home/learn_more',
'cpi' => 'cpi/index',
'<controller:\w+>' => '<controller>/index', //this is the line you need to add
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<controller:\[\w\-]+>/<action:\[\w\-]+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\[\w\-]+>/<action:\[\w\-]+>/<code:\w+>'=>'<controller>/<action>',
'<controller:\[\w\-]+>/<action:\[\w\-]+>'=>'<controller>/<action>',
答案 2 :(得分:0)
尝试查看主机配置文件。例如,在类似* nix的操作系统中,它拥有自己的(一个主机文件)文件,现在让我们看看
(我的,你会有另一个)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName *ServerName*
DocumentRoot /home/nick/public_html/sitefolder
# this one is for any folder without rules
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
# this one for custom folder
<Directory /home/nick/public_html/sitefolder/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All # this one we need to change!
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
这是默认配置文件。但你应该重新检查
<Directory /home/nick/public_html/sitefolder/>
)规则,而不是第一个!帮助我找到合适的网址。
PS:是的,我知道我们可以做出更多改变以使我们的主机更安全,但现在我们谈论的是不使用Yii工作路线(和mod_rewrite)。