笨蛋尝试使用 mod_write 正则表达式进行重定向
我很难让这个合作。基本上,我尝试将网站的提要重定向到 Feedburner,但我不希望任何带有参数的提要 URL 进行重定向。
例如:
mysite.com/feed/
应重定向到 http://feeds.feedburner.com/mysite
但此 URL 不应重定向:
mysite.com /feed/?post_type=custom
现在,第二个 URL 被重定向到 http://feeds.feedburner.com/mysite?post_type=custom
,这是有问题的。我希望该 URL 保持不变。任何带有 ? 的 URL /feed/ 之后应该保持原样。
这是我的代码:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/mysite [R=302,NC,L]
</IfModule>
我尝试了 RewriteRule,但无法让它合作。我尝试对问号进行否定前瞻,但它没有改变任何东西。
使用 ([_0-9a-z-]+)?
的原因是 WordPress 创建类似 5 个不同的提要。
预先感谢您的任何帮助。自从几个月前我沉迷于正则表达式以来,我感觉自己像个傻瓜,但现在我做不到。
I'm having a hell of a time getting this to cooperate. Basically I'm trying to redirect my site's feeds to Feedburner, but I don't want any feed URLs with parameters on them to redirect.
For example:
mysite.com/feed/
should redirect to http://feeds.feedburner.com/mysite
But this URL should not redirect:
mysite.com/feed/?post_type=custom
Right now that second URL is getting redirected to http://feeds.feedburner.com/mysite?post_type=custom
and that's problematic. I want that URL to remain untouched. Any URL that has a ? after the /feed/ should be left alone.
Here's my code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/mysite [R=302,NC,L]
</IfModule>
I played around with the RewriteRule but I couldn't get it to cooperate. I tried doing a Negative Lookahead for a question mark, but it didn't alter anything.
The reason ([_0-9a-z-]+)?
is used is because WordPress creates like 5 different feeds.
Thanks in advance for any help. I feel like a dummy since I was heavy into regex a couple months ago and now I can't do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
URL 中的问号在 RewriteRule 中不匹配,因为它匹配 REQUEST_URI,而不是 QUERY_STRING。如果您希望在存在查询字符串时不重定向,您应该能够仅添加 RewriteCond %{QUERY_STRING} ^$
然后,只有在查询字符串为空时才会重定向。
The question mark in a URL is not matched against in the RewriteRule, as this matches against the REQUEST_URI, not the QUERY_STRING. If you wish to not redirect if there is a query string you should be able to just add in a RewriteCond %{QUERY_STRING} ^$
Then it will only redirect if the query string is empty.