首页 » 网站推广 » 伪静态改为php技巧_php网站启用伪静态的方法

伪静态改为php技巧_php网站启用伪静态的方法

访客 2024-11-21 0

扫一扫用手机浏览

文章目录 [+]

PHP网站开启伪静态的步骤

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

伪静态改为php技巧_php网站启用伪静态的方法

#LoadModule rewrite_module modules/mod_rewrite.so

伪静态改为php技巧_php网站启用伪静态的方法
(图片来自网络侵删)

把前面#去掉。
没有则添加,但必选独占一行,使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网站启用伪静态的方法的详细内容,更多请关注其它干系文章!

更多技巧请《转发 + 关注》哦!

标签:

相关文章

今日头条算法引领个化信息时代的变革

信息爆炸时代已经到来。每个人都是信息的接收者和传播者。面对海量的信息,人们往往感到无所适从。为了解决这一问题,各大互联网公司纷纷推...

网站推广 2025-01-31 阅读1 评论0

今日头条算法信息推荐的秘密武器

信息爆炸的时代已经来临。人们每天都会接触到大量的信息,而如何从这些信息中筛选出有价值的内容,成为了亟待解决的问题。今日头条算法作为...

网站推广 2025-01-31 阅读1 评论0

今日头条算法精准推荐背后的技术奥秘

信息爆炸的时代已经来临。我们每天都要面对海量的信息,如何从这些信息中筛选出自己感兴趣的内容,成为了每个人都关心的问题。今日头条作为...

网站推广 2025-01-31 阅读1 评论0