我有一个 Magento 网站托管在托管服务器上,我们需要使用两个 .htaccess 文件,第一个文件用于将所有请求重定向到子文件夹/current/src/
,并直接放在public_html
Web 根目录中
RewriteEngine On
RewriteRule ^$ /current/src/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/current/src/
RewriteRule ^(.*)$ /current/src/$1
第二个 .htaccess 是 Magento 1.9 附带的,稍加修改,直接放在/current/src/
附言:我只包括处理 URL 重写的部分
#########################################################################
################## Coding Basics Magento .htaccess File #################
# http://codingbasics.net/magento-htaccess-file-optimized-speed-security-seo/ #
#########################################################################
##### Block unwanted Crawler Bots that clog your server #####
RewriteCond %{HTTP_USER_AGENT} MJ12bot
RewriteRule .* - [F]
RewriteCond %{HTTP_USER_AGENT} 80legs [NC]
RewriteRule ^ - [F]
##### Search Engine redirects and rewrites for SEO purposes #####
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# I added this bloc to add a trailing Slash to every URL except
# any URL that contains any Query String for SEO purpose
########################################################################
RewriteCond %{ENV:REDIRECT_STATUS} ^.
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1/ [R=301,L,QSA]
########################################################################
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>
- 下面的 .htaccess 文件在没有我添加的块的情况下工作正常,现在我成功保留了任何包含尾随 / 的原始 URL,例如:
{Server_URL}/en/blog/
- 分类页面无尾随 /
{Server_URL}/en/category/sub-category
301 重定向至
{Server_URL}/en/category/sub-category/
和
{Server_URL}/en/category/sub-category?dir=asc&limit=36&order=price
301 重定向至
{Server_URL}/en/category/sub-category/?dir=asc&limit=36&order=price
- 产品页面无尾随 /
{Server_URL}/en/product-url-key
301 重定向至
{Server_URL}/en/product-url-key/
301 重定向至
{Server_URL}/en/product-url-key
... 错误太多_重定向