


PHP pseudo-static (url rewrite mod_rewrite rewrite)_PHP tutorial
mod_rewrite is a very powerful function of Apache, which can realize pseudo-static pages. Below I will explain in detail how to use it! Very useful for beginners!
1. Check whether Apache supports mod_rewrite
Check the environment configuration through the phpinfo() function provided by php, and find "Loaded Modules" through Ctrl+F, which lists all modules that apache2handler has opened. If it includes "mod_rewrite" is already supported and no further settings are required.
If "mod_rewrite" is not turned on, open the httpd.conf file under your apache installation directory "/apache/conf/", use Ctrl+F to find "LoadModule rewrite_module", and change the "#" sign in front Just delete it.
If it is not found, go to the "LoadModule" area, add "LoadModule rewrite_module modules/mod_rewrite.so" in the last line (required to be an exclusive line), and then restart the apache server.
2. Let the apache server support .htaccess
How to make your local APACHE server support ".htaccess"? In fact, you can make APACHE support .htaccess by simply modifying apache's httpd.conf settings. Open the httpd.conf file (where is it? In the CONF directory of the APACHE directory), open it with a text editor and search for
Options FollowSymLinks
AllowOverride None
changed to
Options FollowSymLinks
AllowOverride All
That’s it.
3. Create .htaccess file
If you are on the Windows platform, I really don’t know how to create the “.htaccess” file at first, because this file actually has no file name, only an extension. This file cannot be created through ordinary methods, so don’t worry. , I will tell you three methods right away: The three methods all first create a text file of htaccess.txt (of course, you can choose the name of this text file as you like), and then there are three ways to rename this file:
(1) Open it with Notepad, click File – Save As, enter ".htaccess" in the file name window, pay attention to the entire green part, which includes English quotes, and then click Save.
(2) Enter the cmd command window, use cd to switch the folder where the htaccess.txt file was just created, then enter the command: rename htaccess.txt .htaccess, and then click the Enter key on the keyboard.
(3) Connect the folder where htaccess.txt is located through ftp, and rename it through ftp software.
4.rewrite rule learning
After we create a new .htaccess file, write the following content in it:
RewriteEngine on #rewriteengine is the rewrite engine switch on is on and off is off
RewriteRule ([0-9]{1,})$ index.php?id=$1
Let me explain RewriteRule: RewriteRule is a rewriting rule that supports regular expressions. The above ([0-9]{1,}) refers to the number, and $ is the end mark, indicating that it ends with a number. !
Okay, now we can implement pseudo-static pages, write down the following rules:
RewriteEngine On
RewriteRule ^index.html$ index.php
RewriteRule ^new-(d+).html$ newxx.php?uid=$1

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
