Introduction to PHP Yii Open source Framework (ii) to modify the access path of Yii Web site

Source: Internet
Author: User
Tags php file resource yii

The default Web site access path looks like this:

Http://127.0.0.1:8080/zuizen/index.php?r=admin/UserInfo/admin

This path is unfriendly to search engines and needs to be changed to the following form:

Http://127.0.0.1:8080/zuizen/admin/UserInfo/admin.html

The following steps achieve the above requirements:

1 Modify Apache configuration so that it supports rewriting:

Open the Apache configuration file httpd.conf: Open the Apache mod_rewrite module:

Remove the "#" symbol before the LoadModule rewrite_module modules/mod_rewrite.so

Ensure "allowoverride all" in <directory "d:/var/www/html" ></Directory>

Restart Apache.

2 Modify Yii Web site configuration:

Locate the Urlmanager under components in the/protected/config/main.php in the project and modify it to:

' Urlmanager ' =>array (

' Urlformat ' => ' path ',

' Rules ' =>array (),

' Showscriptname ' =>false,

' Urlsuffix ' => '. html ',

),

Urlformat set Path: The default value is get, that is, the requested resource (/path/to/entryscript.php?name1=value1&name2=value2 ...) is represented in the URL by a got parameter R. Path is represented by a path:

(/path/to/entryscript.php/name1/value1/name2/value2 ...) )。

Showscriptname set to false: the Portal file "/index.php" does not appear in the URL, at which point you need to set the forwarding rules for the Web server to forward requests that are not explicitly resource locations to the portal file.

Rules set the parameter mapping mode of the action, expressed in regular expressions, see Curlmanager

3 Add rewrite permissions for the Web site:

Add the file ". htaccess" at the same level as the site root index.php file, which reads 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

4 can now be accessed using the desired path format.

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.