Heim  >  Artikel  >  Backend-Entwicklung  >  Apache schaltet pseudostatisch ein

Apache schaltet pseudostatisch ein

王林
王林Original
2019-10-09 11:58:343698Durchsuche

Apache schaltet pseudostatisch ein

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

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>

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

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

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

推荐教程:PHP视频教程

Das obige ist der detaillierte Inhalt vonApache schaltet pseudostatisch ein. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:Apache pseudostatisch zu NginxNächster Artikel:Apache pseudostatisch zu Nginx