modrewite不工作在.htaccess工作、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...

我想写重写规则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.)

阅读全文

相关推荐

最新文章