"Nginx rewrite URL" when the project has multiple portal files

Source: Internet
Author: User

In order to make the URL more beautiful, we do not want to see the URL of the word php (forced gecko).

However, when our PHP project has multiple entry files, (if there are index.php, admin.php, app.php, api.php four entry files), in the non-processing state, the URL will show such a scene:

www.example.com/index.php/xxx/xxx/...

www.example.com/admin.php/xxx/xxx/...

www.example.com/app.php/xxx/xxx/...

www.example.com/admin.php/xxx/xxx/...

At this point, we can use the rewrite function of our server, to transform Url,apache and nginx have this function. I'm using nginx here.

In the nginx.conf file, write this:

Server {Listen the;        server_name localhost; Root"D:/phpstudy/www/blog/webroot";        Index index.php; ########################################## #隐藏. PHP Location/ {                if(!-e $request _filename) {# # # When the project has multiple portal files # admin.ph P Entrance Rewrite^/admin/(. *) $/admin.php/$1Last ; # app.php Entrance # rewrite^/app/(. *) $/app.php/$1Last ; # api.php Entrance # rewrite^/api/(. *) $/api.php/$1Last ; # # # Before the URL filter, then go index.php entrance rewrite^/(. *) $/index.php/$1Last ; }} ######################################### #pathinfo mode location~ \.php ($|/) {Fastcgi_pass127.0.0.1:9000;            Fastcgi_index index.php; Fastcgi_split_path_info^ (. +\.php) (. *)$;            Fastcgi_param path_info $fastcgi _path_info;            Fastcgi_param script_filename $document _root$fastcgi_script_name;        Include Fastcgi_params; }}

"Nginx rewrite URL" when the project has multiple portal files

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.