Home > Backend Development > PHP Tutorial > Yii Url rewriting under IIS, iisyiiurl rewriting_PHP tutorial

Yii Url rewriting under IIS, iisyiiurl rewriting_PHP tutorial

WBOY
Release: 2016-07-13 10:15:57
Original
1289 people have browsed it

Yii Url rewriting, iisyiiurl rewriting under IIS

 

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
Copy after login

The automatically generated web.config is as follows

<span><?</span><span>xml version="1.0" encoding="UTF-8"</span><span>?></span>
<span><</span><span>configuration</span><span>></span>
    <span><</span><span>system.webServer</span><span>></span>
        <span><</span><span>directoryBrowse </span><span>enabled</span><span>="false"</span> <span>/></span>
        <span><</span><span>rewrite</span><span>></span>
            <span><</span><span>rules</span><span>></span>
                <span><</span><span>rule </span><span>name</span><span>="已导入的规则 1"</span><span>></span>
                    <span><</span><span>match </span><span>url</span><span>="."</span><span> ignoreCase</span><span>="false"</span> <span>/></span>
                    <span><</span><span>conditions </span><span>logicalGrouping</span><span>="MatchAll"</span><span>></span>
                        <span><</span><span>add </span><span>input</span><span>="{REQUEST_FILENAME}"</span><span> matchType</span><span>="IsFile"</span><span> ignoreCase</span><span>="false"</span><span> negate</span><span>="true"</span> <span>/></span>
                        <span><</span><span>add </span><span>input</span><span>="{REQUEST_FILENAME}"</span><span> matchType</span><span>="IsDirectory"</span><span> ignoreCase</span><span>="false"</span><span> negate</span><span>="true"</span> <span>/></span>
                    <span></</span><span>conditions</span><span>></span>
                    <span><</span><span>action </span><span>type</span><span>="Rewrite"</span><span> url</span><span>="index.php"</span> <span>/></span>
                <span></</span><span>rule</span><span>></span>
            <span></</span><span>rules</span><span>></span>
        <span></</span><span>rewrite</span><span>></span>
    <span></</span><span>system.webServer</span><span>></span>
<span></</span><span>configuration</span><span>></span>
Copy after login

5. Modify config.php

'urlManager' => <span>array</span><span>(
            </span>'urlFormat' => 'path', <span>//</span><span>URL 格式。共支持两种格式: 'path' 格式( 如:/path/to/EntryScript.php/name1/value1/name2/value2... ) 和'get' 格式( 如:/path/to/EntryScript.php?name1=value1&name2=value2...)。当使用'path'格式时,需要设置如下的规则:</span>
            'showScriptName'=><span>false</span>,
<span>//</span><span>            'urlSuffix'=>'.html',</span>
            'rules' => <span>array</span>(<span>//</span><span>URL 规则。语法:<参数名:正则表达式></span>
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',<span>
            )</span>,<span>
        )</span>,
Copy after login

How to rewrite the YII framework under IIS server to change the URL

It seems that "URL_MODE"=>2 is added to the conf file in the conf directory. I don't know if this is the case

After YII rewrites the URL rules, how can the original old address become the new address when loading?

You can only manually match the old address rules and then jump to the new address.

Example:
if ( preg_match( '/cate\_detail/[^\.]+/i' ,$_SERVICE['REQUEST_URI'] ) )
{
$this->redirect($this->createUrl('category/detail', array('cate'=>'Literature')) , true, 301);
}

My URL structure originally was /cate_detail/literature.html, but later it was changed to /cate/literature.html. Just add the above code to the init() method of Controller.php, the parent class of all controllers

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/899448.htmlTechArticleYii Url rewriting under IIS, iisyiiurl rewriting Options +FollowSymLinks IndexIgnore */* RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template