4

私はYiiフレームワークの初心者です。構成ファイルのURLマネージャーのコメントを解除し、次のようなURLスキームを取得しました。

http://localhost/mysite/index.php/displayAll

URLにindex.phpを含めたくありません。だから私はこのようなURLが欲しい

http://localhost/mysite/displayAll

これを達成するために、私は何をすべきか。私はURLマネージャーといくつかのhtaccessで遊んでいましたが、何もうまくいきませんでした。

助けてください

4

4 に答える 4

9

.htaccessには、次のものが含まれている必要があります。

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

次に、urlManagerコンポーネントをメインの構成ファイルに追加する必要があります。

array(
    ......
    'components'=>array(
        ......
        'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName'=>false,
            'rules'=>array(
                'pattern1'=>'route1',
                'pattern2'=>'route2',
                'pattern3'=>'route3',
            ),
        ),
    ),
);

'showScriptName' => falseに注意してください。これにより、生成されたURLから'index.php'が非表示になります。

YiiのURLマネージャーに関するすべてを見つけるには、Yiiのドキュメントでこのトピックを確認してください: http ://www.yiiframework.com/doc/guide/1.1/en/topics.url

于 2012-08-04T12:33:06.680 に答える
3

試す:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?mysite/(.*)$ /mysite/index.php/$1 [L]
于 2012-08-04T11:42:35.797 に答える
0

httpd.confで、を探します。

     LoadModule rewrite_module modules/mod_rewrite.so 

(まだ削除されていない場合は、行の先頭から#を削除します。)

              OR 
     In wamp click on wampserver-> Apache -> Apache Modules and enable rewrite_module.

index.phpがあるディレクトリに.htaccessを作成し、次のコードを貼り付けます。

IndexIgnore */*
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

そしてprotected/config / main.php

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

それでもクリーンなURLが得られない場合は、仮想ホスト構成ファイル「httpd-vhosts」に移動して使用している場合は、構成を貼り付けてください。

 <Directory "C:/wamp/www">
    AllowOverride All 
 </Directory> 
于 2013-08-20T12:09:41.530 に答える
0

IIS 7、IIS 7.5、IIS 8、IIS 8.5、IIS 10

  1. URL書き換えモジュールがインストールされていることを確認してください。ここで見つけることができます:http ://www.iis.net/downloads/microsoft/url-rewrite

  2. config/main.phpまたはconfig/web.phpからコメントを削除します

        'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
        ],
    ],
    
  3. Webディレクトリbasic/web / web.configに新しいファイルを作成し、 system.webServerに追加します

    <directoryBrowse enabled="false" />
    
    <rewrite>
        <rules>
        <rule name="Hide Yii Index" stopProcessing="true">
            <match url="." ignoreCase="false" />
            <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            </conditions>
                <action type="Rewrite" url="index.php" appendQueryString="true" />
        </rule> 
        </rules>
    </rewrite>
    

結果の例:http:// localhost / basic / web / site / contact

于 2016-07-17T17:32:43.413 に答える