Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How yii url hides the .php suffix

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how yii url hides the .php suffix". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Yii url hides the .php suffix: 1, add .htaccess file; 2, add "'urlManager' = > [...]" to the components array in config/web.php; 3, modify apache.

This article operating environment: Windows7 system, yii2.0 version, Dell G3 computer.

How does yii url hide the .php suffix?

Yii framework enables URL beautification, hides index.php [version 2.0]

Url beautification:

Objective: to transfer http://localtest/yii/web/index.php?r=hello/index

Beautified into: http://localtest/yii/web/hello/index

Here I created a new localtest site using wampserver (click here for details) and renamed the basic folder of yii to yii.

Comparing the two addresses above is actually hiding the index.php?r=.

There are two steps here:

1. Add .htaccess files

Add the .htaccess file to the web root directory with the following contents:

If RewriteEngine OnDirectoryIndex index.html index.php# is a directory or file, access the directory or file RewriteCond% {REQUEST_FILENAME}!-d # if the file exists, access the file directly instead of the following RewriteRuleRewriteCond% {REQUEST_FILENAME}!-fRewriteRule. Index.php

You can't create .htaccess directly, you can create a txt file first, and then save as … Save as a file named .htaccess, and select all files as the save type.

2. Configure config/web.php to add this entry to the components array in config/web.php:

'urlManager' = > [/ enable url beautification' enablePrettyUrl' = > true, / hide index.php 'showScriptName' = > false, / disable strict matching mode' enableStrictParsing' = > false, / url suffix name / / 'suffix'= >' .html', 'rules' = > [],]

At this point, you can delete the index.php?r= in the URL. If an error occurs, you can check the configuration of the server. I am using the apache integrated in phpstudy to check the configuration.

In conf\ httpd.conf, open the mod_rewrite module of apache

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

Then modify the AllowOverride of apache

Change AllowOverride None to AllowOverride All

Since I configured the site in conf\ extra\ httpd-vhosts.conf, I need to synchronize to httpd-vhosts.conf to change the AllowOverride None of the corresponding station to AllowOverride All

At this point, I can use http://localtest/yii/web/hello/index

To access http://localtest/yii/web/index.php?r=hello/index

That's all for "how yii url hides the .php suffix". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report