简体   繁体   English

Magento + htaccess + mod_rewrite:强制尾随斜杠和强制小写URL

[英]Magento + htaccess + mod_rewrite: Forcing trailing slash & Force lower case URL

I am trying to make some changes to my htaccess file for my Magento store to force a trailing slash at the end of all URL's that are not a file AND are not .html (product pages). 我正在尝试对我的Magento商店的htaccess文件进行一些更改,以强制在所有不是文件且不是.html(产品页面)的URL结尾处使用尾部斜杠。 At the same time, I am trying to force all lower case in URL's as well. 与此同时,我也试图强制URL中的所有小写。 Both of these are for SEO reasons, as links to /category, /Category, and /category/ are all viewed as different pages by Google. 这两个都是出于搜索引擎优化的原因,因为链接到/ category,/ Category和/ category /都被Google视为不同的页面。

Here is the rewrite section of the .htaccess as it stands: 这是.htaccess的重写部分:

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* index.php [L]

</IfModule>

I was shown these two snippets, the first for forcing lower case, the second for trailing slash: 我看到了这两个片段,第一个用于强制小写,第二个用于尾随斜杠:

RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]

and... 和...

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]

However I don't know exactly how or where to insert these into the existing rewrites so everything works as desired. 但是,我不确切地知道如何或在何处将这些插入到现有的重写中,以便一切按预期工作。

Put this in your .htaccess: 把它放在你的.htaccess中:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [L,R=301]

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^index.php
RewriteCond %{REQUEST_URI} !\.(html|jpg|png|gif)$
RewriteRule ^(.*)$ $1/ [L,R=301]

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* index.php [L]

</IfModule>

and put this in your vhost config or httpd.conf: 并把它放在你的vhost配置或httpd.conf中:

RewriteMap  lc int:tolower

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

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