mod重写在.htaccess中不起作用 [英] mod rewrite not working in .htaccess

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

问题描述

我正在尝试为php网站编写重写器。

I am trying to write rewriterule for php site.

我的网址就像 http://example.com/attorneys?pid= 69

我在.htacess中编写如下:

I write in .htacess as below:

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

两个链接 example.com/attorneys?pid=69 example.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]

因为第一个规则标有 L 标志,如果第一个匹配,则第二个将不会执行。 (请参见有关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.)

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

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