在htaccess中使用重写的友好URL

编程入门 行业动态 更新时间:2024-10-20 06:22:53
本文介绍了在htaccess中使用重写的友好URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个网址

mysite/profile?id=78

我想将其更改为这样

mysite/78/

我该怎么做?

我的htaccess中有此代码,但似乎不起作用.

I have this code in my htaccess, but it seems it's not working.

RewriteRule ^id/([a-zA-Z0-9]+)/$ profile?id=$1

请在这方面指导我.

您的帮助将不胜感激和奖励.

Your help would be greatly appreciated and rewarded.

谢谢!

推荐答案

我非常确定您应该使用RewriteBase指令

I am pretty sure that you should use the RewriteBase directive

RewriteEngine On RewriteBase / # Use the following rule if you want to make the page like a directory RewriteRule ^u/(!(profile.php))$ u/$1/ [R=301,L] # The following rule does the rewrite. RewriteRule ^u/(!(profile.php))/$ profile.php?name=$1 [L]

这会将mysite/u/john/重写为mysite/profile?name=john.

编辑,这是新答案

RewriteEngine On RewriteBase / # Use the following rule if you want to make the page like a directory RewriteRule ^u/(!(profile.php))$ u/$1/ [R=301,L] # The following rule does the rewrite. RewriteRule ^u/(!(profile.php))/$ profile.php?name=$1 [L] # The following rewrite the other way round: RewriteCond %{REQUEST_URI} ^/profile.php RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /profile.php RewriteCond %{QUERY_STRING} name=([^&]+) RewriteRule ^profile.php$ u/%1? [R=301,L]

更多推荐

在htaccess中使用重写的友好URL

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

发布评论

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

>www.elefans.com

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