Home php教程 php手册 php实现伪静态的方法

php实现伪静态的方法

Jun 06, 2016 pm 07:55 PM
linux php accomplish method Community forum Enter static

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 1.检测Apache是否支持mod_rewrite 通过php提供的phpinfo()函数查看环境配置,通过Ctrl+F查找到"Loaded Modules",其中列出了所有apache2handler已经开启的模块,如果里面包括"mod_rewrite",则已经支

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  1.检测Apache是否支持mod_rewrite

  通过php提供的phpinfo()函数查看环境配置,通过Ctrl+F查找到"Loaded Modules",其中列出了所有apache2handler已经开启的模块,如果里面包括"mod_rewrite",则已经支持,不再需要继续设置。

  如果没有开启"mod_rewrite",则打开目录 您的apache安装目录"/apache/conf/" 下的 httpd.conf 文件,通过Ctrl+F查找到"LoadModule rewrite_module",将前面的"#"号删除即可。

  如果没有查找到,则到"LoadModule" 区域,在最后一行加入"LoadModule rewrite_module ,modules/mod_rewrite.so"(必选独占一行),然后重启apache服务器即可。

  2.让apache服务器支持。htaccess

  如何让自己的本地APACHE服务器支持".htaccess"呢?其实只要简单修改一下apache的httpd.conf设置就可以让 APACHE支 持。htaccess了。打开httpd.conf文件(在那里? APACHE目录的CONF目录里面),

  用文本编辑器打开后,查找

  Options FollowSymLinks

  AllowOverride None

  改为

  Options FollowSymLinks

  AllowOverride All

  就可以了。

  3.建立。htaccess 文件

  有1种最简单的方法建立。htaccess文件:

  用记事本 打开,点击文件?另存为,在文件名窗口输入".htaccess",注意是整个绿色部分,

  也就是包含英文引号,然后点击保存就行了。

  4.rewrite规则学习

  我们新建一个。htaccess文件之后,就在里面写入以下内容:

  RewriteEngine on #rewriteengine为重写引擎开关on为开启off为关闭

  RewriteRule ([0-9]{1,})$index.php?id=$1

  我讲解一下RewriteRule:RewriteRule是重写规则,支持正则表达式的,上面的([0-9]{1,})是指由数

  字组成的,$是结束标志,说明是以数字结束!

  好吧,现在我们可以实现伪静态页面了,写下一下的规则:

  RewriteEngine on

  RewriteRule ([a-zA-Z]{1,})-([0-9]{1,})。html$index.php?action=$1&id=$2

  ([a-zA-Z]{1,})-([0-9]{1,})。html$是规则,index.php?action=$1&id=$2是要替换的格式,$1代表第

  一个括号匹配的值,$2代表第二个,如此类推!!

  我们写一个处理的PHP脚本:

  index.php

  PHP代码

  echo '你的Action是:' . $_GET['action'];

  echo '

  ';

  echo '你的ID是:' . $_GET['id'];

  ?>

  好了,我们现在在浏览器中输入:

  localhost/page-18.html

  输出的是:

  你的Action是:page

  你的ID是:18

php实现伪静态的方法

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

How to install deepseek How to install deepseek Feb 19, 2025 pm 05:48 PM

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Ouyi okx installation package is directly included Ouyi okx installation package is directly included Feb 21, 2025 pm 08:00 PM

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

See all articles