YII tutorial-Yiiurl rewriting

Source: Internet
Author: User
If you want to rewrite the yii url, you can change the url to a better note and remove the index. php part. Comparison before and after conversion

If you want to rewrite the yii url, you can change the url to a better note and remove the index. php part. Comparison before and after conversion:

Before modification: http: // localhost/index. php? R = site/page? View = about

After modification: http: // localhost/site/page? View = about

I checked some information to complete the above results. My environment is: apache2 (httpd-2.2.21), PHP5.3.8, Yii 1.1.8

STEP 1

First, ensure that apache2 has a rewrite module. you can see the apache module through phpinfo.

I spent a lot of time in this step, no matter how the compilation is done, it is completed through the following:

Cd/home/qteqpid/Software/httpd-2.2.3/modules/mappers/
/Usr/local/apache2/bin/apxs-c mod_rewrite.c
/Usr/local/apache2/bin/apxs-I-a-n mod_rewrite mod_rewrite.la
If no error occurs, mod_rewrite.so will be displayed in/usr/local/apache2/modules/. Note that you can only add the following line in the httpd. conf file ,,
LoadModule rewrite_module modules/mod_rewrite.so

Restart apache.

STEP 2

Modify protected/config/main. php as follows:

'Urlmanager' => array (
'Urlformat' => 'path ',
'Showscriptname' => false, // This step hides the index. php linked to the code.
'Rules' => array (
' / '=>' /View ',
' // '=>' /',
' /'=>' /',
),
),

After this step, all links in yii will not see the index. php, but it should also be known to add index when apache receives such a url request. php, which requires url rewriting.

STEP 3

With step 1, you can add the. htaccess directory under the root directory of the yii project (same as the index. php directory) and write:


Options + FollowSymLinks
IndexIgnore */*
RewriteEngine On

RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
RewriteRule. index. php

OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.