Mod_Rewrite 通配符的/附加 [英] Mod_Rewrite wildcard's / appending

查看:50
本文介绍了Mod_Rewrite 通配符的/附加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网站上制定一个类别的全局规则,其中某些内容会自动添加到 url 的末尾.

I'm trying to make a global rule with a category on my website where something automatically gets added to the end of url.

示例:

www.websitename.com/category/page.html 被更改为 www.websitename.com/category/page.html?somethingelse 并且随后的任何 www.websitename.com/category/* 都被附加了 ?somethingelse

www.websitename.com/category/page.html gets changed to www.websitename.com/category/page.html?somethingelse and anything subsequently which is www.websitename.com/category/* gets appended with ?somethingelse

我知道我可以通过单独的 301 重定向来做到这一点,但是否有一条规则适用于所有情况?因为当前每次创建新页面时,都必须进行新的重定向.

I know I could do this with individual 301 redirects but is there a one rule fits all? as every time a new page is created currently, a new redirect would have to be made.

推荐答案

如果我理解正确的话,这应该可以解决问题:

If I'm understanding you correctly, this should do the trick:

RewriteRule ^category/(.*.html)$ category/$1?somethingelse

这意味着每个以 category 开头并以 html 结尾的 URL 将被重写以在末尾添加 ?somethingelse.示例:

This means that every URL that starts with category and ends with html will be rewritten to add ?somethingelse at the end. Examples:

http://www.websitename.com/category/foo.html => http://www.websitename.com/category/foo.html?somethingelse
http://www.websitename.com/category/bar.html => http://www.websitename.com/category/bar.html?somethingelse

这篇关于Mod_Rewrite 通配符的/附加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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