Get the App
SLTechnology News&Howtos  ›  Development  › 

How does php remove the .php suffix from url?

Shulou Source: shulou.com Published: 2022-06-02 22:31:33 09月11日 Update

This article mainly explains "how php removes the .php suffix from url". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to remove the .php suffix from url by php".

Php remove the .php suffix in url: 1, find and open the "extra/httpd-vhosts.conf" file under apache; 2, remove the php suffix by configuring pseudo-static.

This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer

How does PHP remove the .php suffix from url?

Like a link like this

Http://example.com/xxx.php

How to turn it into

Http://example.com/xxx and can be accessed in the browser

Is it using .htaccess? How?

Methods:

Just be pseudo-static.

Demo:

Localhost/news.php?type=music&id=100 We hope that this address can replace localhost/news-music-id100.html with the following access url

To do this, under extra/httpd-vhosts.conf under apache, make the following settings:

DocumentRoot "C:/myenv/apache/htdocs/static2" # Directory configuration node, which is used to specify files or pictures in this directory. Access rights # set the error page of the virtual host, welcome page ServerName www.hsp.com#, you can specify whether to allow people to access # Allow from all# whether to list the file directory structure # if you want to list how indexes does not want none#Options indexes# to configure the first page of the website, how to configure the DirectoryIndex abc.html abc2.html# error page Guide users to introduce a new page errorDocument 404 / 404.html# to configure our rewrite rule RewriteEngine On [x4] # rewrite rules if aaa.html jumps to news.php#$1 to indicate reverse reference, the content of the first subexpression # indicates that if the content of the subexpression is directly referenced in the regular specification Then use\ n# if it is later, use $nRewriteRule news- ([a-zA-Z] +)-id (\ d+)\ .html$ news.php?type=$1 [x5] & id=$2 so far, I believe you have a deeper understanding of "how php removes the .php suffix in url". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Suffix configuration content page file method is in directory website expression rule error static learning practical deeper size host practice interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi Shulou Tech Info Huawei Microsoft