最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

php网站启用伪静态的方法

来源:动视网 责编:小采 时间:2020-11-27 14:19:00
文档

php网站启用伪静态的方法

php网站启用伪静态的方法:PHP网站开启伪静态的步骤1、打开apache的配置文件httpd.conf找到#LoadModule rewrite_module modules/mod_rewrite.so把前面#去掉。没有则添加,但必选独占一行,使apache支持 mod_rewrite 模块,找到<Directory "D
推荐度:
导读php网站启用伪静态的方法:PHP网站开启伪静态的步骤1、打开apache的配置文件httpd.conf找到#LoadModule rewrite_module modules/mod_rewrite.so把前面#去掉。没有则添加,但必选独占一行,使apache支持 mod_rewrite 模块,找到<Directory "D


PHP网站开启伪静态的步骤

1、打开apache的配置文件httpd.conf找到

#LoadModule rewrite_module modules/mod_rewrite.so

把前面#去掉。没有则添加,但必选独占一行,使apache支持 mod_rewrite 模块,找到

<Directory "D:/ApacheServer/web">
 #
 # Possible values for the Options directive are "None", "All",
 # or any combination of:
 # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
 #
 # Note that "MultiViews" must be named *explicitly* --- "Options All"
 # doesn't give it to you.
 #
 # The Options directive is both complicated and important. Please see
 # http://httpd.apache.org/docs/2.2/mod/core.html#options
 # for more information.
 #
 Options Indexes FollowSymLinks

 #
 # AllowOverride controls what directives may be placed in .htaccess files.
 # It can be "All", "None", or any combination of the keywords:
 # Options FileInfo AuthConfig Limit
 #
 AllowOverride None

 #
 # Controls who can get stuff from this server.
 #
 Order allow,deny
 Allow from all

</Directory>

3、把AllowOverride None换成AllowOverride All使apache支持.htaccess文件

4、重启apache服务器

在要启用伪静态的 PHP 项目根目录下建立 .htaccess 文件,在 .htaccess 文件中输入内容

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteRule index.html$ index.php
 RewriteRule index-([1-9]+[0-9]*).html$ index.php?p=$1
 RewriteRule ([a-z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2</IfModule>

注释:

RewriteEngine 为重写引擎开关,on为开启,off为关闭。

RewriteRule 是路由转向规则,之前路径为浏览器中要输入路径,这里可以用正则表达式表达。之前路径为浏览器中要输入路径,这里可以用正则表达式表达。+空格 后路径为后台实际转向路径, 转向后台实际路径时可以传参数。

例子里的后台页面可以用GET[′p′]GET[′p′]_GET[‘action’] GET[‘id′]来接收GET[‘id′]来接收1 代表浏览器路径中输入的第一个正则表达式的值,以此类推,$2代表第二个正则表达式的值 RewriteRule 路由转向规则里正则表达式用括号 () 括起来。

在项目下 index.php 页面内写入内容

<?php
if ($_GET ['p']) {
 echo "p : " . $_GET ['p'];
}

if ($_GET ['action']) {
 echo "action : " . $_GET ['action'];
}

if ($_GET ['id']) {
 echo "id : " . $_GET ['id'];
}
?>

推荐教程:PHP视频教程

文档

php网站启用伪静态的方法

php网站启用伪静态的方法:PHP网站开启伪静态的步骤1、打开apache的配置文件httpd.conf找到#LoadModule rewrite_module modules/mod_rewrite.so把前面#去掉。没有则添加,但必选独占一行,使apache支持 mod_rewrite 模块,找到<Directory "D
推荐度:
标签: 网站 方法 的方法
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top