简体   繁体   English

htaccess基于查询字符串的网址

[英]htaccess querystring based urls

Suppose my website is www.example.com 假设我的网站是www.example.com

Earlier the urls of my website was like this www.example.com/php/bookdetails.php?bid=33 以前,我网站的网址是这样的www.example.com/php/bookdetails.php?bid=33

Last week i changed the urls of my site to this www.example.com/bookdetails/33 上周,我将网站的网址更改为www.example.com/bookdetails/33

and wrote an htacces like this 并写了这样的htacces

RewriteRule ^bookdetails/(.*)$ php/bookSearchResult.php?bid=$1

The problem is that there are some external site using my earlier URL structure ( www.example.com/php/bookdetails.php?bid=33 ) and what i want is to redirect it to my new URL structure ( www.example.com/bookdetails/33 ). 问题是,有些外部站点正在使用我以前的URL结构( www.example.com/php/bookdetails.php?bid=33 ),而我想要的是将其重定向到我的新URL结构( www.example.com / bookdetails / 33 )。

I know it can be possible in htaccess, but i have no idea how to do it 我知道htaccess中有可能,但是我不知道该怎么做

RewriteRule ^php/bookdetails\\.php\\?bid=(\\d+)$ bookdetails/$1 [L,R=301]

A PCRE to match the old format, capturing the number, the new URL with the reference to the captured number, Last rule, Redirect with HTTP status 301 (moved permanently) 匹配旧格式的PCRE,捕获号码,引用捕获号码的新URL,上一条规则,使用HTTP状态301重定向(永久移动)

( Tested it for syntax, but not to ensure that it works exactly . I'm fairly sure that if this isn't it, it should be close.) 对它进行了语法测试,但不能确保它能正常工作 。我很确定,如果不是,则应该关闭它。)

Make sure this rule is before the other you mentioned rewriting to the proper php URL, or you'll get a 500 for an infinitely looping rewrite. 确保此规则在您提到的另一个规则之前重写到正确的php URL,否则无限循环重写将获得500。

The Rewrite Guide and the Advanced Rewrite Guide are invaluable resources for examples. 重写指南高级重写指南是示例的宝贵资源。

EDIT: 编辑:

BTW, this is a duplicate of .htaccess and seo friendly urls , and probably several others, for additional ideas. 顺便说一句,这是.htaccess和seo友好url的重复,还可能是其他几个URL ,以获取其他想法。 (I should have looked for a dup first.) (我本来应该先找一个dup。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM