您的位置:首页 > 编程语言 > PHP开发

php URL 路径重写 rewrite

2013-05-31 08:06 387 查看
假如这里有一个 test.php文件 里面有如下代码:

<?php

$id=$_GET["id"];

echo $id;

?>

首先 apache文件里

打开Apache配置文件httpd.conf,找到如下:#LoadModule rewrite_module modules/mod_rewrite.so

开启rewrite,去点前面"#"

二.开始重载Allowoverride

查找apache配置文件找到如下

<Directory />

Options FollowSymLinks

AllowOverride None

</Directory>

将AllowOverride None改为 AllowOverride All

在htaccess中暂时了解到三种url重定义

<IFMODULE mod_rewrite.c>

RewriteEngine On

#RewriteBase / (若文件在根目录下不必定义)

#RewriteRule ^t_(.*).html$ test.php?id=$1 [NC](打开test.php以t_id.html 比如 t_2.html 页面输出 id=2)

RewriteRule ^([0-9]+)$ test.php?id=$1 [NC](直接输入id 比如 localhost/test/2 页面输出 id=2)

RewriteRule ^index.html$ index.php [NC](直接输入index.html可打开index.php这个页面)

</IFMODULE>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: