本文介绍了在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
发布评论