的.htaccess改写$

编程入门 行业动态 更新时间:2024-10-05 09:27:49
本文介绍了的.htaccess改写$ _ GET变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下页面:

mysite/news/index.php?tag=tag&name=name&id=id

我想重写这一点,以便它去那种如下:

mysite/news/tag/name-id

这方面的一个完整的例子是。

foobar/news/apple/the-new-iphone-5-9001

另外经过我重写这个URL将我仍然能够获取数据,我通常会如:

$ _ GET ['标签'] //将苹果 $ _GET ['名称'] //将是全新的,与iPhone 5 $ _GET ['身份证'] //将9001

解决方案

添加这在Web根为.htaccess。

RewriteEngine叙述上 的RewriteBase / 重写规则^新闻/([^ /] +)/(+?) - (\ d +)/ $ /news/index.php?tag=$1&name=$2&id=$3

I have the following page:

mysite/news/index.php?tag=tag&name=name&id=id

I want to rewrite this so that it goes kind of as follows

mysite/news/tag/name-id

A full example of this would be.

foobar/news/apple/the-new-iphone-5-9001

Also after I rewrite this URL will I still be able to pull data as I would normally for instance:

$_GET['tag'] //would be apple $_GET['name'] //would be the-new-iphone-5 $_GET['id'] //would be 9001

解决方案

Add this to .htaccess in your web root.

RewriteEngine On RewriteBase / RewriteRule ^news/([^/]+)/(.+?)-(\d+)/?$ /news/index.php?tag=$1&name=$2&id=$3

更多推荐

的.htaccess改写$

本文发布于:2023-11-02 06:31:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551627.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!