目的:使得URL地址看起来能更舒服些
实现:用统一的规则来简化URL地址
本质:正则替换
适用:URL传参不是很多,且个数一致

具体操作如下:
1.修改apache的配置文件httpd.conf
    1).去掉前面的#号注释LoadModule rewrite_module modules/mod_rewrite.so
    2).
    <Directory />
        Options FollowSymLinks
        AllowOverride None    //None改为All
        Order deny,allow
        Deny from all
    </Directory>
2. 在相应目录下新建一“.htaccess”文件,可用editplus另存为。注意是:没有名字,后缀为htaccess。如“.htaccess”在web根目录下则对所有链接有效。
3. 编写“.htaccess”
    rewriteengine on  #开启引擎
    RewriteRule ^test/(\w+)$ test.php?var=$1    
    RewriteRule ^test/(\w+)-(\w+)$ test.php?$1=$2
    RewriteRule ^\d+$ test.php

对应test.php
<?php
   var_dump($_GET);
?>

如报错“Internal Server Error”,先检查apache的rewrite是否开启,然后检查“.htaccess”是否有语法错误,如“RewriteRule ^\8+$ test.php”就会报此错。

或加上以下:

<IfModule mod_rewrite.c>
 RewriteEngine On
 </IfModule>

下班了,就记到这,改天补充。

相关文章:

  • 2021-11-12
  • 2021-09-29
  • 2021-05-30
  • 2021-08-05
  • 2021-12-17
  • 2021-12-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
  • 2021-12-29
  • 2021-11-28
  • 2022-12-23
  • 2021-09-05
相关资源
相似解决方案