Home > Backend Development > PHP Tutorial > apache turns on pseudo-static

apache turns on pseudo-static

王林
Release: 2023-04-07 14:14:02
Original
3827 people have browsed it

apache turns on pseudo-static

apache开启PHP的伪静态模式

什么是伪静态?

伪静态又名URL重写,是动态的网址看起来像静态的网址。换句话说就是,动态网页通过重写 URL 方法实现去掉动态网页的参数,但在实际的网页目录中并没有必要实现存在重写的页面。

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、在httpd.conf中配置虚拟主机

# Virtual hosts 启用虚拟主机
Include conf/extra/httpd-vhosts.conf
Copy after login

3、httpd_vhosts.conf文件中,配置相应的选项

<VirtualHost *:80>
  DocumentRoot "C:/myenv/apache/htdocs/static3"
  ServerName www.hsp.com
  <Directory "C:/myenv/apache/htdocs/static3">
#Deny from All 403错误提示
Allow from All
#如果文件目录在apache目录外面,注释掉optinos 则,不能列表.
options +Indexes
#下面这个表示可以去读取 .htaccess文件,也可以直接在虚拟主机中配置.
Allowoverride All
RewriteEngine On
RewriteRule news-id(\d+).html$ error.php?id=$1
#这里可以设置多个重写的规则
#RewriteRule news-id.html$ error.php
  </Directory>
 </VirtualHost>
Copy after login

4、在相应的目录下编写.htaccess 重写规则

如果在linux下可以直接创建;如果是在windows平台下,用记事本创建一个文件,比如abc.txt,然后另存为 .htaccess文件即可。

5、重写规则,也可以直接在配置虚拟主机的段配置

推荐教程:PHP视频教程

The above is the detailed content of apache turns on pseudo-static. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template