2016-10-26 46 views
0

我的代码以URL运行:如何隐藏在Yii框架从我的网址的index.php

http://localhost/yii/index.php/Adminlogin 

我想要的URL看起来像:

http://localhost/yii/Adminlogin 

.htaccess文件

Options +FollowSymLinks 
IndexIgnore */* 
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 

main.php

'urlManager'=>array(
     'urlFormat'=>'path', 
     'showScriptName'=>false, 
     'rules'=>array(
      'redirect/<redirectUrl>'=>'site/index', 
      'login'=>'site/login', 
      'privacy'=>'site/privacy', 
      'password'=>'site/forgot', 
      '<controller:\w+>/<id:\d+>'=>'<controller>/view', 
      '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', 
      '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
     ), 
    ), 
+0

可能的重复[如何隐藏yii的index.php文件在apache/.htaccess/mod \ _rewrite?](http://stackoverflow.com/questions/26061591/how-can-i -hidden-the-index-php-file-for-yii-in-apache-htaccess-mod-rewrite) –

+0

你可以参考这个文档URL以供你参考:http://stackoverflow.com/documentation/yii/6143/设置在你的主要的php文件#t = 201610270410382135132 –

回答

1

RewriteRule^index.php [L]代替RewriteRule . index.php

+0

它不工作 – Shubhangi

0

使用此在您的main.php

'urlFormat'=>'path', 
'showScriptName'=>false, 

,并在下面的htaccess的使用,

RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA] 
0

试试这个

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php(.*) [NC] 
RewriteRule ^(.*)index\.php(.*)$ http://%{HTTP_HOST}$1/$2 [R=301,L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php(.*) [NC] 
RewriteRule ^index\.php(.*)$ http://%{HTTP_HOST}$1 [R=301,L] 
0

而且,......记得AllowOverride在主要的Apache配置:

<Directory "/path/to/your/yii.sample/web/"> 
    Options FollowSymLinks Multiviews 
    MultiviewsMatch Any 
    AllowOverride All 
    Require all granted 
    allow from all 
</Directory> 

有没有可能是你的web/.htaccess是正确的,但你的Apache决不允许你

0

我的htaccess会看起来像

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

and in main.php

'urlManager'=>array(
    'urlFormat'=>'path', 
    'showScriptName'=>false, 
    'caseSensitive'=>false, 
    'rules'=>array(
     '<controller:\w+>/<id:\d+>'=>'<controller>/view', 
     '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', 
     '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
    ), 
),