Magento,将带有 index.php 的 URL 重定向到没有它的 URL
Magento, redirect URLs with index.php to URLs without it
我正在建立一个 Magento 网站,它不在任何子目录中,例如 /shop
。
之前网站上的每个 URL 都在域名旁边附加 index.php
,例如管理面板是 example.com/index.php/admin
。
我在 Magento 的管理面板中启用了 Mod_rewrite 并添加了一个包含以下内容的 .htaccess
文件以确保 example.com/admin
确实进入了管理面板等等。它确实有效。
这是 htaccess
配置:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
问题是,当我手动输入 example.com/index.php/admin
时,它会按预期将我带到管理面板,但 URL 保持不变,我希望它重定向到右侧 URL这是 example.com/admin
但我做不到。
我是否必须向 htaccess
添加任何配置或者是否与 Magento 相关?
您可以使用以下重写规则来执行此操作:
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) / [R=301,NE,L]
这将检查 url 是否包含 index.php
,如果包含则重定向到没有 index.php 的 url。
我正在建立一个 Magento 网站,它不在任何子目录中,例如 /shop
。
之前网站上的每个 URL 都在域名旁边附加 index.php
,例如管理面板是 example.com/index.php/admin
。
我在 Magento 的管理面板中启用了 Mod_rewrite 并添加了一个包含以下内容的 .htaccess
文件以确保 example.com/admin
确实进入了管理面板等等。它确实有效。
这是 htaccess
配置:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
问题是,当我手动输入 example.com/index.php/admin
时,它会按预期将我带到管理面板,但 URL 保持不变,我希望它重定向到右侧 URL这是 example.com/admin
但我做不到。
我是否必须向 htaccess
添加任何配置或者是否与 Magento 相关?
您可以使用以下重写规则来执行此操作:
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) / [R=301,NE,L]
这将检查 url 是否包含 index.php
,如果包含则重定向到没有 index.php 的 url。