Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这个.htaccess和Yii urlManager设置有什么问题?_.htaccess_Url Rewriting_Yii - Fatal编程技术网

这个.htaccess和Yii urlManager设置有什么问题?

这个.htaccess和Yii urlManager设置有什么问题?,.htaccess,url-rewriting,yii,.htaccess,Url Rewriting,Yii,我在一个子目录下有一个yii网站,例如 http://localhost/~username/maindirectory/yiiapp/ 我的htaccess文件: DirectoryIndex index.php index.html index.htm Options +FollowSymLinks IndexIgnore */* <IfModule mod_rewrite.c> RewriteEngine on RewriteBase /yiiapp # if a direc

我在一个子目录下有一个yii网站,例如

http://localhost/~username/maindirectory/yiiapp/

我的htaccess文件:

DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /yiiapp

# 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>
问题:

DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /yiiapp

# 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>
假设我访问:

  • 第一步:
    http://localhost/~username/maindirectory/yiiapp/
  • 第二步:点击主页上的任何链接(默认的yii应用程序),比如说
    关于我们
    页面
  • 第三步:
    http://localhost/~username/maindirectory/yiiapp/site/page?view=about
  • 第四步:点击链接上的任意一个(假设是同一页)
  • url看起来像:
    http://localhost/yiiapp/site/page?view=about
所以:所有链接都可以通过以下方式访问:
http://localhost/yiiapp/....
,而不是从链接中删除index.php,同时删除字符串b/w
localhost
和基本目录

我已经试过了,需要在localhost上使用相同的url,显然没有使用子域

请帮我解决这个问题。

部分答案:

问题是您正在重定向到同一域上的绝对URL。
URL可能看起来像
/yiiapp/site/page?view=about
。然而,这会导致
http://localhost/yiiapp/site/page?view=about
。您必须预先添加相对于域的网站目录(不确定我是否正确表达)

例如,
a href
标记中的URL应该类似于
/~username/maindirectory/yiiapp/site/page?view=about
,因此您必须从某个地方预先添加
/~username/maindirectory
部分。

请尝试以下操作:

'urlManager'=>array(
    ....
    'baseUrl' => '/~username/maindirectory/yiiapp',
    ....

因此,在.htaccess中,RewriteBase
/~username/maindir/yiiapp
修复了问题,而不是
'baseUrl'=>'/~username/maindirectory/yiiapp'
config/main.php中的东西

以下是完整的.htaccess文件:

DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~username/maindir/yiiapp

# 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>
DirectoryIndex.php index.html index.htm
选项+FollowSymLinks
IndexIgnore*/*
重新启动发动机
RewriteBase/~username/maindir/yiiapp
#如果存在目录或文件,请直接使用它
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
#否则将其转发到index.php
重写规则。index.php

你是对的,但问题是url是使用yii framework createurl函数或使用菜单类生成的,例如
$this->widget('zii.widgets.CMenu',array('items'=>array('label'=>'Home','url'=>array('/site/index')),
不起作用:(,每次单击时,它都会将baseUrl添加到url中