Home Backend Development PHP Tutorial 浅析ThinkPHP中的pathinfo模式和URL重写_PHP

浅析ThinkPHP中的pathinfo模式和URL重写_PHP

Jun 01, 2016 am 11:58 AM
url rewrite

ThinkPHP

复制代码 代码如下:
http://serverName/appName/module/action/id/1/

这个就是pathinfo模式

在不考虑路由的情况下,第一个参数会被解析成模块名称(如果启用了分组的话,则依次往后递推),第二个参数会被解析成操作,后面的参数是显式传递的,而且必须成对出现,例如:

复制代码 代码如下:
http://serverName/appName/module/action/year/2008/month/09/day/21/

通常的URL里面含有index.php,为了达到更好的SEO效果可能需要去掉URL里面的index.php ,通过URL重写的方式可以达到这种效果,通常需要服务器开启URL_REWRITE模块才能支持。
下面是Apache的配置过程,可以参考下:
1、httpd.conf配置文件中加载了mod_rewrite.so模块
2、AllowOverride None 将None改为 All
3、确保URL_MODEL设置为2
4、把下面的内容保存为.htaccess文件放到入口文件的同级目录下

复制代码 代码如下:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

对于重来没接触过.htacces文件的可以百度一些,这里提醒一下,保存的文件名就是 .htaccess,可能看起来只有后缀,就是这样,别又在前面加个  ***.htaccess。

重启Apache之后,原来的
http://serverName/index.php/Blog/read/id/1
就可以通过访问
http://serverName/Blog/read/id/1
简化了URL地址

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Nginx for request redirection and URL rewriting How to use Nginx for request redirection and URL rewriting Aug 01, 2023 pm 10:45 PM

How to use Nginx for request redirection and URL rewriting. As a high-performance web server and reverse proxy server, Nginx, in addition to providing basic request processing, can also use its powerful redirection and URL rewriting functions to process requests. further processing. This article will introduce how to use Nginx for request redirection and URL rewriting, with code examples. Request redirection Request redirection refers to redirecting the request to another URL after receiving the client request. Nginx provides two ways to implement

How does PHP handle URL rewriting and beautification? How does PHP handle URL rewriting and beautification? Jun 29, 2023 am 08:21 AM

PHP is a scripting language widely used in web development, and it handles the needs of URL rewriting and beautification well. URL rewriting and beautification is a technique that changes the URL of a website to make it more readable and user-friendly, improving user experience and search engine optimization. URL rewriting is mainly achieved by modifying the website's server configuration file (such as the .htaccess file of the Apache server). Then use some functions and features in PHP to map the rewritten URL with the original URL. UR

How to use Nginx for redirection and URL rewriting of HTTP requests How to use Nginx for redirection and URL rewriting of HTTP requests Aug 02, 2023 pm 03:57 PM

How to use Nginx for HTTP request redirection and URL rewriting Nginx is a high-performance web server and reverse proxy server. It also provides powerful features to manage HTTP request redirection and URL rewriting. In this article, we will introduce how to use Nginx configuration files to implement these functions and provide code examples to help readers better understand. HTTP request redirection HTTP request redirection refers to redirecting a request from one URL to another URL. This is very emotional

Improve user experience: remove index.php from DZ homepage Improve user experience: remove index.php from DZ homepage Mar 12, 2024 pm 09:51 PM

In the process of improving website user experience, optimizing page loading speed is a crucial part. Removing index.php from the web link can make the website link simpler and more beautiful, and it is also beneficial to search engine optimization and user experience improvement. Next, we will explain in detail how to remove index.php from the DZ (Discuz) forum homepage through code, thereby improving user experience. First of all, we need to make it clear that Discuz is a very well-known forum software. The website link contains i by default.

Using routing components to implement URL rewriting and parameter parsing in PHP Using routing components to implement URL rewriting and parameter parsing in PHP Oct 15, 2023 pm 04:21 PM

Using routing components in PHP to implement URL rewriting and parameter parsing When using PHP to develop websites, URL routing is a very important function. Through URL rewriting and parameter parsing, we can convert originally complex URLs into concise and friendly URL forms, improving user experience and search engine optimization. 1. URL rewriting URL rewriting refers to converting URLs that originally contain dynamic parameters into static, easy-to-understand URL forms. The function of URL rewriting can be implemented using routing components. First, we need a route

Preventing URL Rewriting Attacks: Website Security Development Practices Preventing URL Rewriting Attacks: Website Security Development Practices Jun 30, 2023 pm 03:45 PM

In today's digital age, website security issues are becoming increasingly important. Among them, URL rewriting attacks are widely used in the process of hacking and data leakage. URL rewriting attacks refer to hackers taking advantage of website vulnerabilities to modify URLs to obtain unauthorized information or steal users' sensitive data. To prevent URL rewriting attacks, developers need to adopt a series of secure development practices. This article will introduce some common URL rewriting attack methods and provide some recommended preventive measures. First, let’s understand some common URL rewriting attacks

How to solve URL rewriting and routing issues in PHP development How to solve URL rewriting and routing issues in PHP development Jul 02, 2023 pm 10:01 PM

How to solve the problems of URL rewriting and routing in PHP development. In web development, URL rewriting and routing are very important concepts and technologies, and they are especially common in PHP development. URL rewriting can improve user experience and SEO, while routing can help us better organize and manage code. This article will introduce how to solve URL rewriting and routing problems in PHP development. 1. URL rewriting URL rewriting is the process of converting dynamic URLs into beautiful and easy-to-understand static URLs. In PHP development, we can

Nginx rewrites URL configuration practice to optimize website directory structure and SEO Nginx rewrites URL configuration practice to optimize website directory structure and SEO Jul 04, 2023 am 08:34 AM

Nginx rewrites URL configuration practice to optimize website directory structure and SEO Introduction: Nginx is a high-performance web server and reverse proxy server that is widely used to build and optimize websites. One of the important functions is URL rewriting. By configuring Nginx's URL rewriting rules, we can optimize the directory structure of the website and improve user experience and SEO. 1. Why you need to rewrite URLs and beautify URLs: Friendly URLs are more readable, easy to remember, and more attractive for users. By URL

See all articles