modrewite不工作在.htaccess [英] mod rewite not working in .htaccess

查看:141
本文介绍了modrewite不工作在.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写重写规则PHP的网站。

I am trying to write rewriterule for php site.

我的网址是像 http://xyz.com/attorneys?pid=69

我写.htacess如下:

I write in .htacess as below:

RewriteEngine On
RewriteRule ^attorneys/([0-9]+)/?$ attorneys&pid=$1 [NC,L] 

这两个链接 xyz.com/attorneys?pid=69 xyz.com/attorneys/69 作品

我怎样才能使浏览器知道,如果它得到的第一个环节就必须拿出第二个浏览器。

How can I make the browser know that if it get the first link it have to show the second one in browser.

在此先感谢。

推荐答案

所以,你要重定向 http://xyz.com/attorneys?pid=69 http://xyz.com/attorneys/69 ?之后的另一条规则的第一条规则应该做的伎俩(!):

So you want to redirect http://xyz.com/attorneys?pid=69 to http://xyz.com/attorneys/69? Another rule after(!) the first rule should do the trick:

RewriteEngine On
RewriteRule ^attorneys/([0-9]+)/?$ attorneys&pid=$1 [NC,L] 
RewriteRule ^attorneys&pid=([0-9]+)$ attorneys/$1 [NC,L,R=301]

由于第一条规则标有标志,第二个将不若第一场比赛中执行。 (见这里的mod_rewrite标志的文档。)

Because the first rule is marked with the L flag, the second won't be executed if the first matches. (See the documentation of mod_rewrite flags here.)

这篇关于modrewite不工作在.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆