search
HomePHP FrameworkYIIyii url hide index.php

yii url hide index.php

Sep 07, 2020 am 10:14 AM
index.phpyii

Yii url hide index.php method: first add the ".htaccess" file in the web root directory; then modify the configuration "config/web.php"; finally change "AllowOverride None" to "AllowOverride All" ;" That's it.

yii url hide index.php

Recommended: "PHP Video Tutorial" "yii Tutorial"

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

url beautification

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

is beautified into: http://localtest/yii/web/hello/index

Here I used wampserver to create a new localtest site (click here for details) , and rename 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 access http://localtest/yii/web/index.php?r=hello/index

The above is the detailed content of yii url hide index.php. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Is it easy to migrate a Laravel Project to Yii?Is it easy to migrate a Laravel Project to Yii?May 09, 2025 am 12:01 AM

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

Essential Soft Skills for Yii Developers: Communication and CollaborationEssential Soft Skills for Yii Developers: Communication and CollaborationMay 08, 2025 am 12:11 AM

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 MVC : What are the best benefits?Laravel MVC : What are the best benefits?May 07, 2025 pm 03:53 PM

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

Yii: Is It Still Relevant in Modern Web Development?Yii: Is It Still Relevant in Modern Web Development?May 01, 2025 am 12:27 AM

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

The Longevity of Yii: Reasons for Its EnduranceThe Longevity of Yii: Reasons for Its EnduranceApr 30, 2025 am 12:22 AM

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.

Yii: Exploring Its Current UsageYii: Exploring Its Current UsageApr 29, 2025 am 12:52 AM

Yii is still suitable for projects that require high performance and flexibility in modern web development. 1) Yii is a high-performance framework based on PHP, following the MVC architecture. 2) Its advantages lie in its efficient, simplified and component-based design. 3) Performance optimization is mainly achieved through cache and ORM. 4) With the emergence of the new framework, the use of Yii has changed.

Yii and PHP: Developing Dynamic WebsitesYii and PHP: Developing Dynamic WebsitesApr 28, 2025 am 12:09 AM

Yii and PHP can create dynamic websites. 1) Yii is a high-performance PHP framework that simplifies web application development. 2) Yii provides MVC architecture, ORM, cache and other functions, which are suitable for large-scale application development. 3) Use Yii's basic and advanced features to quickly build a website. 4) Pay attention to configuration, namespace and database connection issues, and use logs and debugging tools for debugging. 5) Improve performance through caching and optimization queries, and follow best practices to improve code quality.

Yii's Features: Examining Its AdvantagesYii's Features: Examining Its AdvantagesApr 27, 2025 am 12:03 AM

The Yii framework stands out in the PHP framework, and its advantages include: 1. MVC architecture and component design to improve code organization and reusability; 2. Gii code generator and ActiveRecord to improve development efficiency; 3. Multiple caching mechanisms to optimize performance; 4. Flexible RBAC system to simplify permission management.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

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.