1. 开启phpstudy扩展,勾选“rewrite_module”

    【教程】phpstudy设置伪静态

  2. 开启phpstudy伪静态支持,打开httpd-conf,修改所有“AllowOverride None”为“AllowOverride All

    【教程】phpstudy设置伪静态

    【教程】phpstudy设置伪静态

  3. 修改并保存后,需重启Apache服务器

  4. 在网站根目录下添加.htaccess文件,创建时需要使用文本编辑器进行另存为创建,比如Editplus

  5. .htaccess文件代码

    RewriteEngine on
  RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2

    其中,html后的$符号表示结束,后跟一个空格,$1和$2表示参数

    测试:

    我的.htaccess代码是

  RewriteEngine on
  RewriteRule article/index-([0-9]{1,}).html$ article/index.html?id=$1

    在浏览器地址栏输入 http://localhost/article/index-1.html 

    会重定向到http://localhost/article/index.html?id=1

    在index.html中获取参数的方法为:

function GetRequest() {  
   var url = window.location.href; //获取url中"?"符后的字串  
   var str=url.split("-")[1].split(".")[0];
   return str;  
}  
console.log(window.location.href);
console.log(GetRequest());

完成。

相关文章:

  • 2021-06-24
  • 2021-10-30
  • 2021-06-29
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
猜你喜欢
  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
  • 2021-10-22
  • 2021-11-23
  • 2021-04-21
  • 2021-11-29
相关资源
相似解决方案