Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento多语言重写SEO修复程序?_Php_.htaccess_Magento_Redirect_Mod Rewrite - Fatal编程技术网

Php Magento多语言重写SEO修复程序?

Php Magento多语言重写SEO修复程序?,php,.htaccess,magento,redirect,mod-rewrite,Php,.htaccess,Magento,Redirect,Mod Rewrite,两年前,我用一种语言与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

两年前,我用一种语言与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允许我们只需登录后端->系统->配置->网络->向URL添加存储代码即可(是)

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

  • example.com/everything\u不带\uu/lang1//\u永久路径
  • example.com/lang1/everything
例如,我需要来自社交网站和其他网站帖子的反向链接的URL不会出现404错误,而是会自动重定向到新结构中的等效页面

所以我想在自然语言中添加这样一个脚本:

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]
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]
乍一看是可行的,但我不能保证。 我希望这会有所帮助
干杯

如果可能的话,您可以使用.htaccess 301 url使用自己的
正则表达式函数

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

这里我给你们举一个分类的例子

使用新的父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]
或者从
yourwebsite.com/category/sub
中完全删除
'/category/'
,最后得到
yourwebsite.com/sub
(“sub”可以是任何url):

重写规则^category/(.*)$1/[R=301,L]

你也可以参考

希望这一定会对您有所帮助。

试试这个:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/lang1/
RewriteCond %{REQUEST_URI} !(.*)/lang2/
RewriteRule ^(.*)$ http://www.domain.com/$1/lang1/ [R=301,L]
我找到了解决办法

嗨,我找到了一个解决方案:

    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]
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]

乍一看是可行的,但我不能保证。我希望这将有助于欢呼

感谢Liyakat的输入,我的问题与示例正好相反,因为我需要在example.com和所有子页面之间添加新的语言代码。也许这可以简化为您的示例。假设/it/是添加到所有不以/en//it/an结尾的页面的路径,对吗<代码>重写规则$.com/(.![it|en])http://example.com/it/ [R=302,L]您应该不必搜索正则表达式。在你的帮助下,你一定能做到this@eliosolutions如果我能帮助你,请不要忘记