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

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)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP and the Web: Exploring its Long-Term Impact PHP and the Web: Exploring its Long-Term Impact Apr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

See all articles