0

2 年前,我用 Magento 用一种语言创建了一个网站,现在我想添加另一种语言。我的实际结构是这样的

  • example.com/category/
  • example.com/about.html
  • example.com/product.html

我想获得这样的结构:

  • example.com/lang1/category/
  • example.com/lang1/about.html
  • example.com/lang1/product.html
  • example.com/lang2/category/
  • example.com/lang2/about.html
  • example.com/lang2/product.html

这没什么大不了的,因为 Magento 允许我简单地登录后端 -> 系统 -> 配置 -> Web -> 将商店代码添加到 Urls(是)

我现在无法进行此设置,因为在此之前我需要修复并从第一个结构重写为新结构。

  • example.com/everything_without_the_/lang1/_path 到永久
  • example.com/lang1/everything

例如,我需要来自社交网站和其他网站的帖子的反向链接的 url 不会出现 404 错误,而是会通过 301 重定向自动重定向到新结构中的等效页面。

所以我想用自然语言添加这样的脚本:

rewrite permanently all the urls which ends not with /lang1/ or /lang2/ to urls with the prefix /lang1/

我知道我可以在 Magento 后端使用此模式手动添加重写规则,但我更想知道是否可以直接从数据库或使用 .htaccess 或 index.php 中的一些脚本批量处理,最重要的是哪一个这些解决方案之间对 SEO 和 SERP 的负面影响较小。


我找到了解决方案

嗨,我找到了解决方案:

    RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC] 
    RewriteCond %{REQUEST_URI} !^/it/
    RewriteCond %{REQUEST_URI} !^/en/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /it/$1  [R=301,L]
    RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
    RewriteRule ^(/)?$ it/index.php [L]

乍一看有效,但我不保证。我希望这会帮助干杯

4

3 回答 3

1

尝试这个:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/lang1/
RewriteCond %{REQUEST_URI} !(.*)/lang2/
RewriteRule ^(.*)$ http://www.domain.com/$1/lang1/ [R=301,L]
于 2013-09-24T10:17:22.103 回答
0

如果可能的话,您可以使用 .htaccess 301 url 自己制作regex function

因为您需要一些特定的要求来处理您的语言部分

这里我给你分类例子

使用新的父 URL 重定向子类别 URL

例子:

category/sub1 redirect to cat/sub1
category/sub2 redirect to cat/sub2
category/sub3 redirect to cat/sub3

如果您更改了父类别 URL,或者即使您想完全删除父 URL,则可能需要这样做:

RewriteRule ^category/(.*) http://www.yourwebsite.com/cat/$1 [R=301, L]

'/category/'或完全删除yourwebsite.com/category/sub并以yourwebsite.com/sub('sub' 可以是任何 url)结束:

RewriteRule ^category/(.*) http://www.yourwebsite.com/ $1/ [R=301, L]

你也可以参考

http://www.learnmagento.org/magento-tutorials/301-redirects-in-magento/

http://blog.maximusbusiness.com/2012/10/magento-url-rewriting-regex-and-301-redirects-tips/

希望这对你有帮助。

于 2013-09-23T14:20:24.140 回答
0

我找到了解决方案

嗨,我找到了解决方案:

RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC] 
RewriteCond %{REQUEST_URI} !^/it/
RewriteCond %{REQUEST_URI} !^/en/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /it/$1  [R=301,L]
RewriteCond %{HTTP_HOST} ^(.)?example.com$ [NC]
RewriteRule ^(/)?$ it/index.php [L]

乍一看有效,但我不保证。我希望这会帮助干杯

于 2013-10-29T00:05:22.903 回答