【问题标题】:.htacces redirect home/category/product to home/product.htaccess 将 home/category/product 重定向到 home/product
【发布时间】:2015-03-05 18:52:59
【问题描述】:

我有一些问题:

1) 如何在 .htaccess 中将 www.home/category1/category2/product1 重定向到 www.home/product1 仅仅因为一个产品有多个页面显然不利于定位广告系列、seo 等。

2) 我正在使用带有默认 .htaccess 文件的 Open Cart,但无法简单地重定向 301 任何页面。获取包含 ?_route_= 的参数 URL 因此,例如我将 301 /category1/product1 重定向到 /product1 并获得一个 URL 为 www.home.com/category1/product1?_route_=category1/product1 和一个错误 404 找不到页面。我的 .htaccess 文件是:

    Options +FollowSymlinks
    RewriteEngine On
    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]

我已经评论了站点地图规则。 我在这里有点没有选择,因为我已经从几个页面建立了手动重定向 301,但是我每次都被重定向到 404 未找到。

非常感谢任何帮助。 谢谢! 干杯。 :)

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    将您的 301 规则放在默认路由规则之前的顶部:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^category1/([^/.]+)/?$ /$1 [L,NC,R=301]
    
    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]
    

    【讨论】:

    • 感谢回复,但仍然对重定向没有影响。
    • 那是因为浏览器缓存。清除浏览器缓存后测试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多