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.