2015-06-02 34 views
0

我在OpenCart(版本1.5.6)網站上更改了一些網址,然後又改變了一次; Google開始提醒我已經有死鏈接,現在我正在嘗試通過在.htaccess中添加手動301重定向來解決問題:我以前每當使用WordPress時都會這樣做。手動301在OpenCart中重定向

我不是可以手動做每個鏈接,我其實更喜歡這種方法。

但是,每當我在.htaccess中添加一行時,它往往被忽略。

下面是我的.htaccess文件的內容:

<Files *.ini> 
Order deny,allow 
Deny from All 
</Files> 

SetEnv PHPRC /home/shopurl/ 
Options +FollowSymlinks 

Options -Indexes 

<FilesMatch "\.(tpl|ini|log)"> 
Order deny,allow 
Deny from all 
</FilesMatch> 

# SEO URL Settings 
RewriteEngine On 

RewriteCond %{HTTP_HOST} ^shopurl.com 
RewriteRule (.*) http://www.shopurl.com/$1 [R=301,L] 


RewriteBase/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L] 
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L] 
RewriteRule ^download/(.*) /index.php?route=error/not_found [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css) 
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] 

<ifModule mod_headers.c> 
    Header set Connection keep-alive 
</ifModule> 

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript 
BrowserMatch ^Mozilla/4 gzip-only-text/html 
BrowserMatch ^Mozilla/4\.0[678] no-gzip 
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
<ifModule mod_headers.c> 
    Header append Vary User-Agent 
</ifModule> 

<FilesMatch "\.(js|css|jpg|png|jpeg|gif|xml|json|txt|pdf|mov|avi|otf|woff|ico|swf)$"> 
    RequestHeader unset Cookie 
    Header unset Cookie 
    Header unset Set-Cookie 
    ErrorDocument 404 'Not Found' 
</FilesMatch> 

我怎樣才能做到這一點成功?

回答

1

添加所有的RewriteRules只是你RewriteBase /線後,像這樣:

... 
RewriteBase/

RewriteRule ^your-url$ /your-new-url [L,R=301] 
RewriteRule ^your-page$ /your-new-page [L,R=301] 
RewriteRule ^your-category$ /your-new-category [L,R=301] 
RewriteRule ^your-product$ /your-new-product [L,R=301] 

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L] 
... 

所以重寫:

http://www.yoursite.com/your-url 
- to - 
http://www.yoursite.com/your-new-url 

等等

+0

隊友,感謝您的幫助。它有效,有點..說有點因爲我有類似於 '重寫規則^主要類別/主新類別[R = 301,L]'(它工作正常) 但我也有類似的東西: '重寫規則^主要類別/子貓/主要新類別/子新貓[R = 301,L]'(不起作用...) – Seb

+0

您應該使用:'重寫規則^主要類別$/main-new-category [R = 301,L]'和'RewriteRule^main-category/sub-cat $/main-new-category/sub-new-cat [R = 301,L]'。請注意RewriteRule的第一個參數後的美元符號。 –

+0

如果您想重寫該類別中的所有產品,我還建議您在最後添加一個帶斜槓和全部匹配的版本。例如:'RewriteRule^main-category /(.*)$/main-new-category/$ 1 [R = 301,L]' –