Home  >  Article  >  php教程  >  Yii method to hide index.php in URL

Yii method to hide index.php in URL

高洛峰
高洛峰Original
2016-12-30 17:02:231782browse

The example in this article describes how Yii hides index.php in the URL. Share it with everyone for your reference, the details are as follows:

1. Modify the main.php under config/:

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

2. Modify the content of the .htaccess file in the root directory of the website as follows:

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

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

For more articles related to Yii’s method of hiding index.php in the URL, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn