fleaphp Development Guide-A2. Using PathInfo and URL overrides

Source: Internet
Author: User
Tags benchmark command line
Development Guide

The fleaphp application determines the controller and action to be executed by parsing the URL address, and the parameters passed to the action method.

By default, the fleaphp application passes

http://www.example.com/index.php?controller=test&action=benchmark&source=1

Such a URL address to access every function of the application. But sometimes you want the URL address to look better, for example, the address above becomes:

http://www.example.com/index.php/test/benchmark/source/1

Or

http://www.example.com/test/benchmark/source/1

To achieve both of these effects, you must use fleaphp support for PathInfo mode and URL rewriting.


PathInfo

To run an application using PathInfo mode, simply set the application options Urlmode for Url_pathinfo .

When using PathInfo, for relative addresses, it must be rewritten as an absolute address using/opening. For example, CSS/STYLE.CSS should be written as/css/style.css, and images/banner.jpg should be written as/images/banner.jpg. In addition to pictures, CSS stylesheets, and JavaScript files, you also use an absolute address for references to other files on your Web site.
This requirement also applies to URL rewrite mode.


URL rewrite

URL rewriting is much more complicated than pathinfo and has some limitations.

    • Currently, fleaphp's support for URL rewriting is very simple, compared with pathinfo, it simply hides the index.php entry file name from the URL address;
    • URL rewriting requires Apache mod_rewrite module support (IIS users can use some commercial software);
    • Apache or. htaccess files must be configured to enable the Mod_rewrite module;
    • For complex directory structures, you have to write more rewrite rules.

Well, I hope the words don't scare you. So take a look at the simplest case:

RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ /index.php/$1 [L]

The overriding rule above is simple, first of all, to enable URL rewriting. It then determines whether the requested file already exists. URL rewriting occurs only if the requested file does not exist.

Save the above to the application root, with the file name. htaccess.

Strangely, in Windows Explorer, you are not allowed to create. htaccess so that only files with extensions. So you must first save the file as a different name, such as App.htaccess. Then enter the command Line window (run the Cmd.exe program from the Start menu) and enter the ren app.htaccess. htaccess command to rename the file.

Finally, the Urlmode option to modify the application settings is url_rewrite.


How to generate a URL address

In the fleaphp application, we should always use the URL () function and the Flea_controller_action::_url () method to generate the URL address. This way, regardless of how the Urlmode option is set, we can ensure that the application generates a URL address to work with.

For example url('test', 'benchmark', array('source' => 1)) , a call like this, under different Urlmode settings, generates a different URL address.

This feature avoids the problem of having to manually replace all the URL addresses because the application modifies the Urlmode option.


More complex, custom URL addresses

The URL routing feature that you are developing to allow your application to get a full custom URL. For example

http://www.example.com/index.php?controller=article&action=view&article_id=123

You can use the address below to replace it. Not only good-looking, but also easy to index the search engine files.

Http://www.example.com/article/123


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.