2011-04-08 43 views
4

我只是將我的網站從asp遷移到opencart。在.htaccess我希望做一些重定向讓我的客戶可以用回舊的鏈接訪問.htaccess opencart重定向301

內的.htaccess

redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us 
redirect 301 /downloads.asp http://www.example.com/downloads 

針對作品的完美,但是,對於下載的網址,聯繫方式,它沒有工作正確。 當我訪問http://www.example.com/downloads.asp它將重定向到http://www.example.com/downloads?_route_=downloads.asp 和Opencart顯示它找不到頁面。 對於http://www.example.com/downloads,我們在後端系統中設置了SEO友好的URL。

我們能夠與訪問

http://www.example.com/information/downloads

http://www.example.com/downloads

,但我們無法與正常的鏈接訪問

http://www.example.com/index.php?route=information/downloads

如下因素是我的全部的.htaccess

# Prevent Direct Access to files 
<FilesMatch "\.(tpl|ini)"> 
Order deny,allow 
Deny from all 
</FilesMatch> 

# SEO URL Settings 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] 

redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us 
redirect 301 /downloads.asp http://www.example.com/downloads 

============ ANOTHER測試========================

我做了一些在我的本地主機上對此進行測試後,我發現這是一個有趣的結果。但是,我的問題仍然沒有解決。

我運行。htaccess的從http://localhost/examplehttp://example(添加的虛擬目錄)

對於http://localhost/example

redirect 301 /example/downloads.asp http://localhost/example/downloads/ 

http://example

redirect 301 /downloads.asp http://example/downloads/ 

然後我試圖,重定向到我的真人版的鏈接,從本地主機(http:// example)

redirect 301 /downloads.asp http://www.example.com/downloads/ 

我訪問http://example/downloads.asp

的瀏覽器重定向到我

http://www.example.com/downloads?route=downloads.asp

風陵渡

在LIVE版本,我沒有添加任何重定向代碼[非常肯定FOR本]

但在真人版,我訪問直接進入

http://www.example.com/downloads

我不知道爲什麼從本地主機重定向301住版本會出來

http://www.example.com/downloads?route=downloads.asp

任何想法?

回答

4

溶液中發現的: htaccess的重定向301 Opencart的v1.5.4.1工作

需要...(和此修復幣)附加代碼: https://github.com/opencart/opencart/pull/142 ...替換的內容: - 目錄/控制器/通用/ seo_url.php - 系統/庫/ url.php

重定向精細: 重寫規則CONTACTO HTTP:.... COM/index.php的路由信息​​= /接觸[R = 301,L]

重定向不工作: 重定向301 CONTACTO HTTP:... COM/index.php的路徑=信息/接觸

驗證。

+0

我替換了'seo_url.php'和'url.php' - 但我需要寫入'htaccess'? – 2016-05-02 08:53:33

3

把它放在路由器的前面。在前面加上.asp和^之後再加$。

# Prevent Direct Access to files 
<FilesMatch "\.(tpl|ini)"> 
Order deny,allow 
Deny from all 
</FilesMatch> 

# SEO URL Settings 
RewriteEngine On 

redirect 301 ^contact.asp$ http://www.example.com/index.php?route=information/contact_us 
redirect 301 ^downloads.asp$ http://www.example.com/downloads 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] 

你爲什麼不重定向接觸/information/contact_us而不是index.php?route=information/contact_us

+0

因爲在Opencart的,對這個沒辦法,你有什麼想法解決這個問題。 ? – Shiro 2011-04-08 01:56:07

+0

我改變了你的代碼,當我訪問http://www.example.com/downloads.asp時,它沒有重定向它,它仍然提醒同一個鏈接http://www.example.com/ – Shiro 2011-04-08 02:02:23

+0

我在我的本地主機上測試了 重定向301 /example/downloads.asp http:// localhost/example/downloads它可以很好地工作,但不能在live版本中運行。 – Shiro 2011-04-08 08:17:26

0

你可以試試「?「在重定向URL結束時,如果它不存在有像第二個URL(它的工作對我來說):

redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us 
redirect 301 /downloads.asp http://www.example.com/downloads?