Home  >  Article  >  Backend Development  >  A brief discussion on URL rewriting in ThinkPHP, a brief discussion on thinkphpurl_PHP tutorial

A brief discussion on URL rewriting in ThinkPHP, a brief discussion on thinkphpurl_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:13:13922browse

A brief discussion on ThinkPHP’s URL rewriting, a brief discussion on thinkphpurl

The result I want is nothing more than to remove index.php from the URL path

The first is to configure .htaccess

Copy code The code is as follows:


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

Because I deploy on apache , I need to find LoadModule rewrite_module modules/mod_rewrite.so in the httpd.conf configuration file and remove the # in front of it, find AllowOverride None and change it to AllowOverride All.

Now accessing localhost/product is valid, but the path obtained by __APP__ or __URL__ or U contains index.php, which is localhost/index.php. It turns out that there is another step, which needs to be in conf/config. Modify or add 'URL_MODEL'=>2,

in php

And because I am trying to deploy conist Enterprise Edition 2.0 based on ThinkPHP, there is such a configuration in config.php 'URL_MODEL' => C ('TOKEN.false_static'), and the value of TOKEN.false_static It is set to 1 during initialization, so. . . The mode is always 1, PATHINFO mode.

Deployed in Sina SAE , it does not support .htaccess and only supports its own configuration file config.yaml, so add the following rewriting format code to config.yaml:

Copy code The code is as follows:

handle:
- rewrite: if(!is_dir() && !is_file() && path~"^(.*)$") goto "index.php/$1"

Isn’t it super simple? If you want to learn more about other pseudo-static aspects, please read the following recommended articles.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/917034.htmlTechArticleA brief talk about ThinkPHP's URL rewriting, a brief talk about thinkphpurl The result I want is nothing more than to remove the index in the URL path .php First, configure .htaccess. Copy the code as follows: IfModule mod_rewrite.c...
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