欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php URL rewrite路径重写一例

程序员文章站 2022-05-01 20:06:37
...
  1. $id=$_GET["id"];
  2. echo $id;
  3. ?>
复制代码

首先 apache文件里

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

开启rewrite,去点前面"#"

二、重载Allowoverride 查找apache配置文件找到如下:

  1. Options FollowSymLinks
  2. AllowOverride None
复制代码

将AllowOverride None 改为 AllowOverride All

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

  1. RewriteEngine On
  2. #RewriteBase / (若文件在根目录下不必定义)
  3. #RewriteRule ^t_(.*).html$ test.php?id=$1 [NC](打开test.php以t_id.html 比如 t_2.html 页面输出 id=2)
  4. RewriteRule ^([0-9]+)$ test.php?id=$1 [NC](直接输入id 比如 localhost/test/2 页面输出 id=2)
  5. RewriteRule ^index.html$ index.php [NC](直接输入index.html可打开index.php这个页面)
复制代码