Mod_rewrite 帮助

发布于 2024-09-28 09:52:03 字数 806 浏览 0 评论 0原文

我正在尝试从日历中删除查询字符串,但我的 mod_rewrite 没有附加查询字符串。

该网站是 http://cacrochester.com/Calendar 如果您单击链接转到其他月份,则查询字符串通常为 http://cacrochester .com/Calendar?currentmonth=2010-11

根据我的以下规则,它只是不附加查询字符串,因此当您单击下个月链接时,它只会保留在十月。我的规则有什么问题吗?

这是我的规则

RewriteCond %{QUERY_STRING} !^$
RewriteRule ^.*$ http://cacrochester.com/Calendar? [NC,R=301,L]

编辑:

我想要的是采用像 http://cacrochester.com/ 这样的网址Calendar?currentmonth=2010-11 并将其转换为类似 http://cacrochester.com/日历/2010-11

I'm trying to remove query strings from my calendar, but my mod_rewrite is not appending the query string.

The website is http://cacrochester.com/Calendar
and if you click the link to go to a different month, the query string is usually http://cacrochester.com/Calendar?currentmonth=2010-11

With my rule below, it just doesn't append the query string so when you click the next month link, it just stays on the month October. What's wrong with my rule?

Here is my rule

RewriteCond %{QUERY_STRING} !^$
RewriteRule ^.*$ http://cacrochester.com/Calendar? [NC,R=301,L]

EDIT:

What i want is to take a url like http://cacrochester.com/Calendar?currentmonth=2010-11 and turn it into something like http://cacrochester.com/Calendar/2010-11

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

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

发布评论

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

评论(2

音盲 2024-10-05 09:52:03

您可能需要您的应用程序输出相对网址,例如“/Calendar/2010-11”。这是一个简单的代码更改。

然后在 Apache 中,您需要重写这些 url,使用:

RewriteRule ^/Calendar/([0-9]+-[0-9]{2})$ /Calendar.php?currentmonth=$1 [NC ,QSA,L]

(您不需要此规则的 RewriteCond。)

使用 R=301 强制重定向只会公开内部 url 方案。我不认为这就是你想要的。

You probably need your app to output relative urls like "/Calendar/2010-11". That's a simple code change.

Then in Apache you'd want to rewrite those urls, using:

RewriteRule ^/Calendar/([0-9]+-[0-9]{2})$ /Calendar.php?currentmonth=$1 [NC,QSA,L]

(You don't want a RewriteCond for this rule.)

Forcing a redirect with R=301 will only expose the internal url scheme. I don't think that's what you want.

花开半夏魅人心 2024-10-05 09:52:03

要在重写时维护查询字符串,请使用 QSA(查询字符串追加)标志。

[NC,R=301,QSA,L]

To maintain query strings when rewriting, use the QSA (query string append) flag.

[NC,R=301,QSA,L]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文