2012-04-07 49 views
0

總之,我們目前遇到了我們的htaccess文件問題。 301重定向到達新的描述的URL,但此外,新的URL後面跟着一個?和舊的網址。我們如何擺脫?和以前的網址,因此它們不會顯示爲結尾。如何防止舊的URL和?通過htaccess包含在301重定向的URL中

我們在網上發現這個問題的例子都沒有出現。任何人都可以請提供一些建議?我們可以使用RewriteRule來阻止這種情況的發生嗎?

這裏的htaccess文件

# begin redirects 
# There are redirects of a number of old pages. Here's a sample of them. 

redirect 301 /index.html http://www.petersommer.com/ 
redirect 301 /escorted-archaeological-tours/turkey/western-lycia-cruise-july/ http://www.petersommer.com/escorted-archaeological-tours/ 

RewriteRule ^gallery/main.php$ http://www.petersommer.com/gallery/ [R=301,L] 
RewriteRule ^pdf/how_to_book.pdf$ http://www.petersommer.com/pdf/how-to-book-holiday.pdf [R=301,L] 

# end redirects 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    Options +FollowSymLinks 
    DirectoryIndex index.php 
    RewriteEngine On 

    RewriteCond $1 !^(images|system|themes|pdf|favicon\.ico|robots\.txt|index\.php) [NC] 
    RewriteRule ^\.htaccess$ - [F] 

    RewriteRule ^favicon\.ico - [L] 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 
</IfModule> 

DirectoryIndex index.php 

的總結不幸的是我不知道什麼是不工作或需要做的事情,以解決它。我認爲它必須是重寫規則中的某些內容,或者我們需要添加一些重寫規則來修復它。

不幸的是,所有的重定向添加?並將舊網址添加到新的重定向網址的末尾。因此,例如:

通到/escorted-archaeological-tours/?/tours2006.html ,而不是僅僅/escorted-archaeological-tours/

重定向 /escorted-archaeological-tours/ 去所有都遵循同樣的模式 - 很遺憾。

如果您可以在重寫規則中看到任何故障或可以識別需要添加的內容,我將非常感激。

回答

0

正如您可能已經注意到的那樣,表示爲RewriteRule的兩個重定向按預期工作,而兩個redirect指令附加舊路徑。

我相信會發生什麼

  • mod_rewrite的踢,如果需要重定向gallery/main.phppdf/how_to_book.pdf,然後每隔URL重寫爲/index.php?/the_requested_path,結束那裏(將L標誌)。請注意查詢參數

  • mod_alias輪到了,看到它必須重定向/index.html,例如,按照指示重定向。但是,在默認情況下,重定向的Apache附加了查詢參數,在這種情況下?/index.html

你能做些什麼

  • 追加?在重定向指令的結束(適用於重寫規則,對重定向未測試)

    redirect 301 /index.html http://www.petersommer.com/? 
    
  • 將您重定向指令在重寫規則

    RewriteRule ^index.html$ http://www.petersommer.com/ [R=301,L] 
    RewriteRule ^escorted-archaeological-tours/turkey/western-lycia-cruise-july/?$ http://www.petersommer.com/escorted-archaeological-tours/ [R=301,L] 
    
+0

非常感謝你的努力幫助。不幸的是,我仍然無法完成工作。你會改變文件中的順序嗎?還有其他建議嗎?感謝您的意見。祝好,彼得 – petersommer 2012-04-09 11:39:00

+0

@petersommer我剛剛在您的網站上檢查了/index.html,重定向按預期工作。也許緩存問題?還是你找到另一種解決方案? – nikoshr 2012-04-11 16:22:24