Table of Contents
PHP+APACHE realizes pseudo-static URLs
Home Backend Development PHP Tutorial PHP+APACHE implements pseudo-static URL_PHP tutorial

PHP+APACHE implements pseudo-static URL_PHP tutorial

Jul 13, 2016 am 10:03 AM
main accomplish article URL pass static

PHP+APACHE realizes pseudo-static URLs

This article mainly introduces the relevant information about PHP+APACHE realizing pseudo-static URLs by using the mod rewrite module. Friends who need it can refer to it.

Apache's mod_rewrite is relatively powerful. When building a website, you can use this module to achieve pseudo-static.

The main steps are as follows:

1. To detect whether Apache has enabled the mod_rewrite function, you can view the environment configuration through the phpinfo() function provided by php and find "Loaded Modules", which lists all modules that have been enabled by apache2handler. If "mod_rewrite" is included, it has been Supported, no further setup is required. If "mod_rewrite" is not enabled, open "/apache/conf/" in the apache directory, find the httpd.conf file, and then find "LoadModule rewrite_module". Delete the "#" in front of it to access this function. If the "LoadModule" area is not found, you can add "LoadModule rewrite_module, modules/mod_rewrite.so" (exclusive line) to the last line, and then restart the apache server. Then check the environment configuration through the phpinfo() function and there will be "mod_rewrite" as an item.

 2. Let the apache server support .htaccess. How to make your local APACHE server support: "htaccess"? Just modify the httpd.conf setting of apache to make APACHE support ".htaccess". Open the httpd.conf file in the CONF directory of the APACHE directory and find: Options FollowSymLinks AllowOverride None and change it to Options FollowSymLinks AllowOverride All.

 3. Create the .htaccess file. When creating the .htaccess file, please note that it cannot be created directly. The method is to use the Save As menu in Notepad, enter: ".htaccess" in the file name window, and then click Save.

4. Rewrite rule learning After creating a new .htaccess file, write the following content in it: RewriteEngine on #rewriteengine is the rewrite engine switch on to open off to close RewriteRule ([0-9]{1,}) $index.php?id=$1 Here, RewriteRule is a rewriting rule, which is a sentence using regular expressions. ([0-9]{1,}) means it is composed of numbers. $ means the end mark, which means it is composed of numbers. Finish! If you want to implement a pseudo-static page, the rules are as follows: RewriteEngine on RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$index.php?action=$1&id= $2 In the regular expression, ([a-zA-Z]{1,})-([0-9]{1,}).html$ is the rule, index.php?action=$1&id=$2 is the format to be replaced, $1 represents the value matched by the first bracket, $2 represents the value of the second bracket, and so on! The test PHP script is as follows: The code in the index.php file is as follows: echo 'Your Action value is:' . $_GET['action']; echo ' '; echo 'The ID value is:' . $_GET['id' ]; ?>

Enter in the browser address bar: localhost/page-18.html The output is: Your Action value is: page ID value: 18

Haha, the rewriting was successful!

Let me share some of my personal experience in configuring pseudo-static:

I started to come into contact with pseudo-static. It looked very magical and I thought it was difficult. In fact, it is very simple. It is to configure a few more virtual domain names in the server, which is similar to the real access URL. Just three steps

A. First, in the Apache Apache module, enable vhost_alias_moudle

B. Modify the httpd.conf file. In this file, search for rewrite. Find LoadModule rewrite_module modules/mod_rewrite.so and remove the #

in front of it.

C. Modify this file and add it to the httpd-vhosts.conf file under the path D:wampbinapacheApache2.2.21confextra. Follow the example and it will be OK

The code is as follows:



ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "d:/wamp/www/dz"
ServerName localhost.www.dz.cn
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common

D. Configure it in the hosts file under the path C:WindowsSystem32driversetc

127.0.0.1 localhost.www.dz.cn Just restart the service. You're done!

**************************************************** ***************************** Happy New Year everyone!

Note: Enter localhost.www.dz.cn in the browser to access it. I added a localhost to distinguish it from the official website address. If you don’t understand anything, please contact me so that we can discuss it together and make progress together!

All your pseudo-static rules are written in the .htaccess file. Since pseudo-static is enabled, this file will be loaded by default. To write this .htaccess file, you need to be able to write regular expressions. Let’s learn some basic regular expressions!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/966915.htmlTechArticlePHP+APACHE implements pseudo-static URLs. This article mainly introduces PHP+APACHE to implement pseudo-static URLs by using the mod rewrite module. For static related information, friends who need it can refer to Apache's mod_...
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 enter the URL in steam? How to open a website on steam How to enter the URL in steam? How to open a website on steam Mar 14, 2024 pm 12:10 PM

If you want to check some relevant information in Steam or share some website links with friends, how do you do it? Can I enter a URL into steam? Of course it is possible. Below I will teach you how to open a URL in Steam. Specific methods: 1. First, we open steam. 2. Click the Settings option. 3. Then switch to the interface tab. 4. Check Show address bar. 5. Then enter the URL in the address bar to use the browser.

How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! Mar 15, 2024 pm 04:13 PM

1. How can you make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! 1. Activate basic rights and interests: original articles can earn profits by advertising, and videos must be original in horizontal screen mode to earn profits. 2. Activate the rights of 100 fans: if the number of fans reaches 100 fans or above, you can get profits from micro headlines, original Q&A creation and Q&A. 3. Insist on original works: Original works include articles, micro headlines, questions, etc., and are required to be more than 300 words. Please note that if illegally plagiarized works are published as original works, credit points will be deducted, and even any profits will be deducted. 4. Verticality: When writing articles in professional fields, you cannot write articles across fields at will. You will not get appropriate recommendations, you will not be able to achieve the professionalism and refinement of your work, and it will be difficult to attract fans and readers. 5. Activity: high activity,

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

How to implement exact division operation in Golang How to implement exact division operation in Golang Feb 20, 2024 pm 10:51 PM

Implementing exact division operations in Golang is a common need, especially in scenarios involving financial calculations or other scenarios that require high-precision calculations. Golang's built-in division operator "/" is calculated for floating point numbers, and sometimes there is a problem of precision loss. In order to solve this problem, we can use third-party libraries or custom functions to implement exact division operations. A common approach is to use the Rat type from the math/big package, which provides a representation of fractions and can be used to implement exact division operations.

Master how Golang enables game development possibilities Master how Golang enables game development possibilities Mar 16, 2024 pm 12:57 PM

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

PHP Game Requirements Implementation Guide PHP Game Requirements Implementation Guide Mar 11, 2024 am 08:45 AM

PHP Game Requirements Implementation Guide With the popularity and development of the Internet, the web game market is becoming more and more popular. Many developers hope to use the PHP language to develop their own web games, and implementing game requirements is a key step. This article will introduce how to use PHP language to implement common game requirements and provide specific code examples. 1. Create game characters In web games, game characters are a very important element. We need to define the attributes of the game character, such as name, level, experience value, etc., and provide methods to operate these

See all articles