2015-11-24 80 views
3

的说明:
我成立了Magento的与存储配置是这样的:Magento的重定向从旧网址新的网址,其中有商店(语言)代码

  • 公司名称 - Webside
    • 总店 - 商店
      • - 商店查看
      • DK - 商店查看

我的链接看起来像:https://my-company.com/shop/

然后我reaslised,这是我的需求错误的配置,我有改变

  • 英语 - Webside
    • 总店 - 商店
      • EN - 商店查看
  • 丹麦 - Webside
    • 总店 - 商店
      • DK - 商店查看


另外,我启用 Magento的功能 “添加商店代码到URL”之前被禁用。
现在我的链接如下所示:https://my-company.com/EN /店/



问题:
既然我已经做网站地图,同时变化没有作出并将其提交给网站管理员,我现在面临的问题在URL中没有商店代码的所有旧链接确实不是不是工作(404代码 - 未找到)。



因为网络管理者和其他原因,我真的想实现这个结果的:
当有人试图打开旧网址是没有存储代码(如https://my-company.com/shop/)之一,我想他是只需将商店代码添加为网址中的第一个网址即可重定向到新网址。



我已经试图通过向我的nginx配置添加一些重写规则来达到这个目的,但是我遇到了无限循环,最后我无法找到正确的重写规则解决方案。 (链接到我的nginx的重写规则问题:Nginx Config Location Regex With Language Code In Url

全部Nginx的配置:

server { 
    # Listen on port 8080 as well as post 443 for SSL connections. 
    listen    8080; 
    listen    443 default ssl; 

server_name   example.com www.example.com; 

large_client_header_buffers 4 16k; 

ssl    on; 

# Specify path to your SSL certificates. 
ssl_certificate   /path/top/certificate.crt; 
ssl_certificate_key  /path/to/key.key; 

ssl_protocols    TLSv1 TLSv1.1 TLSv1.2; 

ssl_ciphers   "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4"; 

ssl_prefer_server_ciphers on; 
ssl_dhparam   /path/to/dh_params.pem; 
    ssl_session_cache  shared:SSL:10m; 
    ssl_session_timeout  10m; 
    keepalive_timeout  70; 
    add_header   Strict-Transport-Security max-age=15768000; 

ssl_stapling   on; 
ssl_stapling_verify  on; 
resolver   8.8.8.8 8.8.4.4 valid=300s; 
resolver_timeout  5s; 

ssl_trusted_certificate  /path/to/certificate.crt; 

# Path to the files in which you wish to store your access and error logs. 
access_log   /path/to/access_log; 
error_log   /path/to/error_log; 

root    /path/to/root/folder; 

location ~* "^/(?![a-z]{2}/)(.+)$" { 
    rewrite  //en/$1 permanent; 
} 

location/{ 
    index   index.htm index.html index.php; 
    try_files  $uri $uri/ @handler; 
} 

# Deny access to specific directories no one in particular needs access to anyways. 
location /app/   { deny all; } 
location /includes/  { deny all; } 
location /lib/   { deny all; } 
location /media/downloadable/ { deny all; } 
location /pkginfo/  { deny all; } 
location /report/config.xml { deny all; } 
location /var/   { deny all; } 

# Allow only those who have a login name and password to view the export folder. Refer to /etc/nginx/htpassword. 
location /var/export/ { 
    auth_basic  "Restricted"; 
    auth_basic_user_file htpasswd; 
    autoindex  on; 
} 

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, etc... 
location ~ /\. { 
    deny   all; 
    access_log  off; 
    log_not_found  off; 
} 

# This redirect is added so to use Magentos common front handler when handling incoming URLs. 
location @handler { 
    rewrite  //index.php?$query_string; 
} 

# Forward paths such as /js/index.php/x.js to their relevant handler. 
location ~ .php/ { 
    rewrite   ^(.*.php)/ $1 last; 
} 

# Handle the exectution of .php files. 
location ~ .php$ { 
    if (!-e $request_filename) { 
     rewrite //index.php last; 
    } 

    expires   off; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass  unix:/path/to/php-fpm.sock; 
    fastcgi_index  index.php; 
    fastcgi_param  HTTPS on; 
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param  MAGE_RUN_CODE en; 
    fastcgi_param  MAGE_RUN_TYPE store; 
    include   fastcgi_params; 
} 

} 
+0

你可以显示你的重写正在产生无限循环?您的重写可能没问题,但这个循环是由您的浏览器引起的,例如, Chrome的内部DNS chrome:// net-internals /#dns – jdm2112

+0

已更新的问题与代码片段 –

+0

大概这是(或曾经)正在工作的网站。您正在发布明确具有重定向循环的代码段。我想我们需要更多的'nginx'配置来理解为什么PHP处理程序被破坏。 –

回答

3

您的网站域3种网址:有漂亮的永久链接这不是真正的文件(例如: /en/shop/),它由内部重写并由控制器处理(即/index.php)。有静态内容是真正的文件(CSS文件,图像,JavaScript),并直接由nginx提供服务。还有过时的网站地图(您想重定向到其他网站)。

问题是您添加的重写规则也与静态内容匹配。

因此,在测试重定向之前,您需要首先提供静态内容。这是通过让try_files看到原来的URI,然后应用新的重写规则,该@handler块内实现:

location @handler { 
    rewrite "^/(?![a-z]{2}/)(.+)$" /en/$1 permanent; 
    rewrite//index.php?$query_string; 
} 

这似乎在我的测试环境中工作,但情况因人而异

0

这个代码我增加了对我的nginx配置,也许会对其他有用,它是修复管理区太:

location/{ 
rewrite "^/(?![a-z]{2}/)(.+)$" /en/$1 permanent; 
    rewrite//index.php?$query_string; 
} 

location /index.php/admin { 
try_files $uri $uri/ /index.php?$args; 
index index.php index.html index.htm; 
} 
相关问题