2012-01-18 28 views
0

我移植了大量的從平面文件的網站內容,以Wordpress和有我的.htaccess重定向爲每個頁面如下:.htaccess重定向 - 這是否適用於頁面中的所有錨鏈接?

redirect 301 /01-chapter1.html http://www.mydomain.com/section1/chapter-1/ 

在這個內容有一些定義爲錨鏈接如下:

<a name="106">Link 106</a> 

我的問題是,將重定向上面也處理這些錨鏈接,使舊的頁面的錨:

http://www.mydomain.com/01-chapter1.html#106 

重新獲得定向到新頁面的錨:

http://www.mydomain.com/section1/chapter-1/#106 

希望它和我沒有實現獨立重定向千錨:(

提前爲你的建議非常感謝的。


ANSWER

好吧,我實現了原來的重定向我張貼:

redirect 301 /01-chapter1.html http://www.mydomain.com/section1/chapter-1/ 

測試這FF/IE/Chrome和無論出於何種原因重定向似乎表現正是我希望不任何附加參數。

外部鏈接:

http://www.mydomain.com/01-chapter1.html#106 

是完全重定向到頁面錨鏈接:

http://www.mydomain.com/section-1/chapter-1/#106 

感謝您的好建議過,但到目前爲止,一切順利!

+0

很好,你發現你自己,但下次在浪費別人的時間之前先做這個簡單的測試。儘管如此,歡迎來到StackOverflow。 – Gerben 2012-01-19 16:16:38

回答

0

不幸的是,它沒有這樣做。看看這個博客文章: http://www.mikeduncan.com/named-anchors-are-not-sent/

你可以嘗試用JavaScript代替客戶端。

編輯:更多信息:

301 Redirect Cheatsheet顯示許多重定向選項。當從Can you write a 301 redirect to an anchor point?收集的信息相結合,意味着我們可以寫類似:雖然

RewriteRule ^01-chapter1.html(#.+)?$ /section1/chapter-1/$1 [R=301,NE] 

不能確定正則表達式的語法,可能需要別的東西。

+0

aw crap - 我有超過4000個指定的錨鏈接被各種外部網站用來訪問我的內容。你提到的這個js選項的任何指針(不是我的包)? – user9373 2012-01-18 13:00:11

+0

查看[redirection cheatsheet](http://www.askapache.com/htaccess/list-of-methods-to-redirect-users-to-different-page.html)。我想你或許可以用mod_rewrite來做到這一點,看看這個問題:http:// stackoverflow。com/questions/386709/can-you-write-a-301-redirect-to-an-point-point – cha0site 2012-01-18 13:15:03

+0

@ user9373我編輯了答案以顯示新信息。 – cha0site 2012-01-18 13:28:14

相關問題