我有一個Apache的配置,具有多個重寫規則,以獲得最可愛的URL重定向,避免重複的搜索引擎優化,等這裏有一個片斷爲例(它的功能多了很多):如何結合Apache重定向?
# 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
這很好,但它恰好產生了很多重定向。一個常見情況如下:
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重定向。
現在,我想所有這些規則被鏈接並只產生一個301重定向,像這樣:
http://example.com/index.php, 301 redirect to http://www.example.com
我知道我可以花一個下午的時間思考和排序規則,以更好的匹配,也我可以創建組合規則。但是這會使已經很長的文件變得複雜。我想要一個標誌,操作數或任何可以執行所有規則的內容,就好像它們在內部所在的位置一樣,只有在每條規則都被抓取後才發出重定向。這甚至有可能嗎?