Yii How to hide the .php suffix in url: 1. Add the .htaccess file; 2. Add "'urlManager' => [...]" to the components array in config/web.php; 3. Just modify apache.
#The operating environment of this article: Windows 7 system, version yii2.0, Dell G3 computer.
yii url How to hide the .php suffix?
Yii framework enables URL beautification, hiding index.php [2.0 version]
url beautification:
Purpose: beautify http://localtest/yii/web/index.php?r=hello/index
into: http://localtest/yii/web/hello/index
Here I used wampserver to create a new localtest site (click here for details), and renamed the basic folder of yii to yii.
Comparing the two addresses above, we actually hide index.php?r=.
There are two steps here:
1. Add the .htaccess file
Add the .htaccess file in the web root directory, the content is:
RewriteEngine On DirectoryIndex index.html index.php # 如果是一个目录或者文件,就访问目录或文件 RewriteCond %{REQUEST_FILENAME} !-d #如果文件存在,就直接访问文件,不进行下面的RewriteRule RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . index.php
Unable To create .htaccess directly, you can first create a txt file, and then save it as..., save the file name as .htaccess, and select all files as the saving type.
2. Configure config/web.php. Add this item to the components array in config/web.php:
'urlManager' => [ // //开启url美化 'enablePrettyUrl' => true, // //隐藏index.php 'showScriptName' => false, // //禁用严格匹配模式 'enableStrictParsing' => false, // //url后缀名称 // 'suffix'=>'.html', 'rules' => [ ], ],
At this time, you can change the index.php?r in the URL =Delete, if a 404 error occurs, you can check the server configuration. I am using apache integrated in phpstudy. You need to check the configuration
conf\httpd.conf and enable 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;
Because I am The site is configured in conf\extra\httpd-vhosts.conf, so it needs to be synchronized to httpd-vhosts.conf to change the AllowOverride None of the corresponding site to AllowOverride All;
At this point, I can use http: //localtest/yii/web/hello/index
to visit http://localtest/yii/web/index.php?r=hello/index
Recommended: " yii tutorial》
The above is the detailed content of How to hide .php suffix in yii url. For more information, please follow other related articles on the PHP Chinese website!

ThemostcommonerrorsinYiiframeworkare"UnknownProperty","InvalidConfiguration","ClassNotFound",and"ValidationErrors".1."UnknownProperty"errorsoccurwhenaccessingnon-existentproperties;ensurepropertiesexi

The key skills that European Yii developers need to possess include: 1. Yii framework proficiency, 2. PHP proficiency, 3. Database management, 4. Front-end skills, 5. RESTful API development, 6. Version control system, 7. Testing and debugging, 8. Security knowledge, 9. Agile methodology, 10. Soft skills, 11. Localization and internationalization, 12. Continuous learning, these skills make developers stand out in the European market.

Yes,theYiicommunityisstillactiveandvibrant.1)TheofficialYiiforumremainsaresourcefordiscussionsandsupport.2)TheGitHubrepositoryshowsregularcommitsandpullrequests,indicatingongoingdevelopment.3)StackOverflowcontinuestohostYii-relatedquestionsandhigh-qu

Migratingalaravel Projecttoyiiishallingbutachieffable WITHIEFLEFLANT.1) Mapoutlaravel component likeroutes, Controllers, Andmodels.2) Translatelaravel's SartisancommandeloequentTooyii's giiandetiverecordeba

Soft skills are crucial to Yii developers because they facilitate team communication and collaboration. 1) Effective communication ensures that the project is progressing smoothly, such as through clear API documentation and regular meetings. 2) Collaborate to enhance team interaction through Yii's tools such as Gii to improve development efficiency.

Laravel'sMVCarchitectureoffersenhancedcodeorganization,improvedmaintainability,andarobustseparationofconcerns.1)Itkeepscodeorganized,makingnavigationandteamworkeasier.2)Itcompartmentalizestheapplication,simplifyingtroubleshootingandmaintenance.3)Itse

Yiiremainsrelevantinmodernwebdevelopmentforprojectsneedingspeedandflexibility.1)Itoffershighperformance,idealforapplicationswherespeediscritical.2)Itsflexibilityallowsfortailoredapplicationstructures.However,ithasasmallercommunityandsteeperlearningcu

Yii frameworks remain strong in many PHP frameworks because of their efficient, simplicity and scalable design concepts. 1) Yii improves development efficiency through "conventional optimization over configuration"; 2) Component-based architecture and powerful ORM system Gii enhances flexibility and development speed; 3) Performance optimization and continuous updates and iterations ensure its sustained competitiveness.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools
