elgentos / module-baseurlpath
允许Magento配置使用基础URL路径而不是根目录,而无需将Magento 2移动到子目录中
1.0.1
2020-10-03 09:29 UTC
Requires
- magento/framework: *
- magento/module-store: *
Requires (Dev)
- phpunit/phpunit: ~6.5.0
README
Magento 2 - Elgentos_BaseUrlPath
允许在系统配置中设置基础URL,而非根目录。
如果您想添加https://my.domain.tld/mypseronalurl/
到基础URL,目前Magento不允许这样做。您只能将storecode添加到路径中或创建带有额外文件的子目录。
如果您只想添加语言代码(除地区代码外)到您的域名,例如 https://my.domain.tld/en/
和 https://my.domain.tld/nl/
,这可能会变得很复杂
安装:第1部分 - 通过composer安装模块
通过运行以下命令安装模块:
composer require elgentos/module-baseurlpath bin/magento module:enable Elgentos_BaseUrlPath bin/magento cache:flush
安装:第2部分 - Nginx MAGE_RUN_CODE
确保您正确设置MAGE_RUN_CODE
映射。默认情况下,在Nginx中,这仅基于$host
名称。
我们将添加$request_uri
到映射中。
# https://{host}/{language}/{magento_request}/ # Most specific match goes first map $host$request_uri $mageRunCode { hostnames; default default; ~other.domain.tld/nl/ other_nl; ~other.domain.tld other_en; ~my.domain.tld/en/ site_en; ~my.domain.tld site_nl; } # fastcgi section fastcgi_param MAGE_RUN_CODE $mageRunCode;
Nginx未映射
或者如果您无法使用Nginx映射。
# https://{host}/{language}/{magento_request}/ # Most specific match goes last # this one is untested thought(sorry for that) set $mageRunCode "default"; if ($host$request_uri ~ other.domain.tld/) { set $mageRunCode "other_en"; } if ($host$request_uri ~ other.domain.tld/nl/) { set $mageRunCode "other_nl"; } if ($host$request_uri ~ my.domain.tld/) { set $mageRunCode "site_nl"; } if ($host$request_uri ~ my.domain.tld/en/) { set $mageRunCode "site_en"; }
配置
安装后,转到 商店
/ 配置
-> 常规
/ Web
-> 基础URL(不安全/安全)
强烈建议在网站或商店视图级别设置这些设置,因为错误可能会导致您无法访问管理页面
商店1:site_en
更新您的base url为 https://my.domain.tld/en/
商店2:site_nl
更新您的base url为 https://my.domain.tld/nl/
静态内容和媒体
为了使静态内容与这些设置一起工作,您需要明确地将这些路径设置为网站的根目录(/
)。