Php 如何正确配置URLmanager规则?

Php 如何正确配置URLmanager规则?,php,.htaccess,yii,yii-url-manager,Php,.htaccess,Yii,Yii Url Manager,我无法在Yii中配置路由项目是3天,所有人都试图帮助。。。 我有: /var/www/-project /var/www/yii-yii框架 /htaccess RewriteEngine On # Put your installation directory here: # If your URL is www.example.com/, use / # If your URL is http://localhost/begin/, use /begin/ RewriteBase /

我无法在Yii中配置路由项目是3天,所有人都试图帮助。。。 我有:

/var/www/-project

/var/www/yii-yii框架

/htaccess

RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is http://localhost/begin/, use /begin/

RewriteBase /

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
php查找

./var/www/protected/config/main.php

'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false,
            'rules'=>array(
              '/'=>'/view',
              '//'=>'/',
              '/'=>'/',
            ),
    ),
当我输入例如107.170.91.28/site/contact时,会显示一个错误404。 服务器107.170.91.28的URL 在本地服务器上。一切顺利。 如果我输入这个URL 107.170.91.28/index.php/site/contact或107.170.91.28/index.php?r=site/contact,它会工作。
请求帮助,因为我尝试了所有设置的方法。

如果这种情况仅发生在服务器上,则可能是因为您已将Apache配置为忽略服务器上的.htaccess指令,或者是因为您未加载/安装“重写模块”

您可以通过在/etc/apache2/apache2.conf中更改来配置apache conf以打开(位置可能因操作系统而异,当然,您也可以仅为应用程序目录打开它)

<Directory>
...
        AllowOverride None
....
</Directory>
之后重新启动apache2

/etc/init.d/apache2 restart


将.htaccess放置在index.php存在的位置。为什么更改url规则?/var/www/.htaccess与/var/www/index.phpI放在同一个文件夹中。我尝试了,但未能正确配置。在本地服务器上有这些规则,一切正常。非常感谢您的帮助!只出现了其他错误(np;如果答案有助于您选择它,那么其他具有类似问题的人将知道如何处理它:)顺便说一句,我不确定您的规则数组是否正常工作..我通常使用这组规则,这可能会解决您的其他问题“'/'=>'/view','/'=>'/'、'/'=>'/',”谢谢你的评论,但一切都没有改变。我已经改变了规则。有趣的是,这是由于不正确的“规则”或某个链接了Yii::app()-request->>baseUrl的东西造成的?
a2enmod rewrite
/etc/init.d/apache2 restart
service apache2 restart