简体   繁体   English

htaccess的magento index.php单一家庭URL重写规则?

[英]htaccess rewrite rule for magento index.php single home URL?

Magento by default listens to 3 possible url's for reaching the home page: 默认情况下,Magento会监听3个可能的网址以访问首页:

  1. https://www.shop.nl/ https://www.shop.nl/
  2. https://www.shop.nl/index.php https://www.shop.nl/index.php
  3. https://www.shop.nl/index.php/ https://www.shop.nl/index.php/

Google doesn't like this behaviour, and i'm trying to optimize my shop for search engines. Google不喜欢这种行为,我正在尝试针对搜索引擎优化我的商店。 So i went to the .htaccess file of Magento and tried to edit the correct rules. 因此,我转到了Magento的.htaccess文件,并尝试编辑正确的规则。 However this does not seem to work. 但是,这似乎不起作用。

I tried replacing line 175: RewriteRule .* index.php [L] with: 我尝试将175行: RewriteRule .* index.php [L]替换为:

RewriteCond %{REQUEST_URI} !^/index.php/admin($|/)
RewriteRule ^index.php(/(.*))? /$2 [R=301,QSA,L]

This because it occured to me that magento's back-end doesn't like that i'm removing the index.php from the URL. 这是因为在我看来magento的后端不喜欢我从URL中删除index.php。 It works for the root URL. 它适用于根URL。 But the problem is i can't view any other pages. 但问题是我无法查看任何其他页面。 All redirect me to the home page. 全部将我重定向到主页。

Does anybody have any suggestions? 有人有什么建议吗? And i also would like to find out why magento is doing this at all. 我也想弄清楚为什么magento会这样做。 I can't figure out how this could be usefull. 我不知道这怎么有用。

Notice: I wonderd if it matters that i am running on suPHP . 注意:我想知道在suPHP上运行是否重要

Add this rule as first rule in your magento .htaccess: 将此规则添加为您的magento .htaccess中的第一条规则

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php/?$ /$1 [L,R=301,NC,NE]

This will remove index.php from original URL (not from the rewritten URI). 这将从原始URL(而不是从重写的URI)中删除index.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM