使用 .htaccess 附加参数

发布于 2024-08-21 17:46:19 字数 368 浏览 4 评论 0原文

我正在与 htaccess 重写命令作斗争,

我所拥有的是

RewriteCond %{HTTP_HOST} ^www.mywebsite.co.uk$
RewriteCond %{REQUEST_URI} !^/subfolder/ 
RewriteRule ^(.*)$ /subfolder/

我有几个 URL 转到同一文件夹,其中一些重定向到子文件夹,然后运行不同的模板。但是,我还需要在重定向的每个页面的末尾附加一个参数,例如?template=2

我不能手动将其添加到末尾,因为有些页面已经有参数,例如/?product=1 - 所以第二个参数需要有&标志不是?符号。

任何帮助表示赞赏

i'm struggling with an htaccess rewrite command

what I have is

RewriteCond %{HTTP_HOST} ^www.mywebsite.co.uk$
RewriteCond %{REQUEST_URI} !^/subfolder/ 
RewriteRule ^(.*)$ /subfolder/

I have a few URLs going to the same folder, some of them redirect to subfolders, which then run different templates. However, I also need to append a parameter to the end of every page that is redirected, eg, ?template=2

I can't just add it to the end manually, because some pages already have parameters, eg /?product=1 - so the second parameter needs to have the & sign not the ? sign.

Any help appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木緿 2024-08-28 17:46:19

您只需在规则末尾添加 QSA 标志:

RewriteRule ^(.*)$ /subfolder/?template=2 [QSA,L]

You just need to add the QSA flag on the end of your rule:

RewriteRule ^(.*)$ /subfolder/?template=2 [QSA,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文