php网站启用伪静态的方法-php教程

资源魔 38 0

PHP网站开启伪动态的步骤

一、关上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>

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

四、重启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开发教程 php开发资料 php开发自学

抱歉,评论功能暂时关闭!