【问题标题】:.htaccess opencart redirect 301.htaccess opencart 重定向 301
【发布时间】:2011-04-08 01:48:27
【问题描述】:

我只是将我的网站从 asp 迁移到 opencart。在 .htaccess 中,我想做一些重定向,以便我的客户可以使用旧链接访问

在 .htaccess 中

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

对于完美运行的“联系我们”,但是对于下载 url,它无法正常运行。 当我访问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

============另一个测试========================

我在本地主机上对此进行了一些测试,我发现这是一个非常有趣的结果。但是,我的问题还没有解决。

我从http://localhost/examplehttp://example 运行.htaccess(添加了虚拟目录)

对于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 版本中,我没有添加任何重定向代码 [非常确定]

但在直播版本中,我是直接输入访问

http://www.example.com/downloads

我不知道为什么会出现从 localhost 重定向 301 到 live 版本

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

有什么想法吗?

【问题讨论】:

    标签: .htaccess redirect opencart


    【解决方案1】:

    找到的解决方案: .htaccess 重定向 301 与 opencart v1.5.4.1 一起使用

    ...所需的其他代码(以及此修复的功劳): https://github.com/opencart/opencart/pull/142 ...替换以下内容: - 目录/控制器/common/seo_url.php - 系统/库/url.php

    重定向罚款: RewriteRule contacto http:..com/index.php?route=information/contact [R=301,L]

    重定向不起作用: 重定向 301 联系人到 http:..com/index.php?route=information/contact

    已验证。

    【讨论】:

    • 我替换了 seo_url.phpurl.php - 但是我需要写什么到 htaccess
    【解决方案2】:

    放在路由器前面。 .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

    【讨论】:

    • 因为在 opencart 中,没有这个选项。你有什么办法解决这个问题吗?
    • 我改成你的代码,当我访问example.com/downloads.asp时,它没有重定向,它仍然在同一链接上提醒example.com/downloads.asp。也许您想尝试下载 opencart 并进行测试。
    • 我在我的 localhost 中使用重定向 301 /example/downloads.asp localhost/example/downloads 进行了测试,它运行良好,但不是在实时版本中。
    • 试试..RewriteRule ^downloads.asp$ http://www.example.com/downloads [R=301,L]
    • @webarto 请再看看我的问题,我添加了更多示例。我不确定是我的网络服务器问题还是什么。
    【解决方案3】:

    如果重定向 url 没有像第二个 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?
    

    【讨论】:

      猜你喜欢
      • 2010-12-07
      • 2016-10-04
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 2011-01-03
      • 2012-03-10
      • 2021-07-22
      • 1970-01-01
      相关资源
      最近更新 更多