自定义重定向不适用于本地主机

Custom redirect not working on the localhost

我在 Magento 根文件夹的 .htaccess 文件中创建了自定义重定向。 magento 的基 url 是 http://127.0.0.1/mymagento/

## enable rewrites

    Options +FollowSymLinks
    RewriteEngine on

    RewriteRule ^kit-rasage.html    /spray-can.html [R=301,L]

但是当我访问http://127.0.0.1/mymagento/kit-rasage.html it redirects to http://127.0.0.1/kit-rasage.html

根目录在httpdconf文件中如下

<Directory "C:/xampp/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride All

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

操作系统是windows 7,我使用的是XAMPP。 如何解决?

经过以下更改后它对我有用。

RewriteBase /mymagento/
RewriteRule ^kit-rasage.html    /spray-can.html [R=301,L]

在本地主机上,我们在 htdocs 文件夹中还有其他目录,因此我们必须添加 RewriteBase /mymagento/,其中 mymagento 是目录名称。