如何结合Apache重定向? [英] How to combine Apache redirects?

查看:114
本文介绍了如何结合Apache重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Apache配置,该配置具有多个重写规则和重定向,以便获得最可爱的URL,防止SEO重复等等.这是一个示例片段(功能更多):

I've got an Apache config that features multiple rewrite rules and redirects in order to get the cutest URLs, prevent duplicates for SEO, etc. Here's a snippet as an example (it features a lot more):

# Redirecting non-www to www 
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Removing index.php
RewriteCond %{REQUEST_URI} index\.php$ [NC]
RewriteRule .* / [R=301,L]

# A big bunch of these
Redirect permanent /old-article.html  http://www.example.com/new-article.html
Redirect permanent /another-old-article.html  http://www.example.com/new-article2.html

这很好用,但是碰巧会产生很多重定向.常见情况如下:

This works well, but it happens to generate a lot of redirects. A common case looks like this:

http://example.com/index.php, 301 redirect to http://www.example.com/index.php
http://www.example.com/index.php, 301 redirect to http://www.example.com

有时会达到4-5次重定向.

It sometimes reaches 4-5 redirects.

现在,我希望将所有这些规则链接在一起,并仅生成一个301重定向,如下所示:

Now, I want all these rules to be chained and generate only one 301 redirect, like this:

http://example.com/index.php, 301 redirect to http://www.example.com

我知道我可以花一个下午的时间思考和排序规则以使其更匹配,并且可以创建组合规则.但这会使原本就很长的文件复杂化.我想要一个标志,操作数或将执行所有规则的命令,就像它们在内部一样,并且仅在爬取每个规则后才发出重定向.这有可能吗?

I know I can spend an afternoon thinking and sorting the rules to a better match, and also that I can create combined rules. But that would complicate an already long file. I want a flag, operand or whatever that will execute all the rules as if they where internal and only issue the redirect once it has crawled every rule. Is this even possible?

推荐答案

从您的RewriteRule中删除[L]标志,它们将被自动组合.

Remove the [L] flag from your RewriteRules, and they will be combined automatically.

这篇关于如何结合Apache重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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