19

我的 magento 安装在 /var/www/magento 下的 Ubuntu Linux 上。这个问题看起来像档案中的一些问题,但实际上有些不同。当我在 Ubuntu Linux 上安装 Magento 时,我启用了 Apache mod_rewrite URL 重写。

当我转到 http://localhost/magento 我的服务器将 URL 重写为 http://localhost/magento/ 并显示页面。然后我单击导航栏中的链接之一,假设它是导航栏项目“foo”。然后magento带我去:

http://localhost/magento/foo.html

显示“未找到”的 apache 页面。

我必须将 URL 更改为 ----->

http://localhost/magento/index.php/foo.html

为了显示页面。

就好像我的 mod_rewrite 工作有问题。

谢谢,

约翰·戈切

配置:系统->配置->(常规->)Web:

使用 Web 服务器重写:是

基本网址:http://localhost/magento

如果我将“用户 Web 服务器重写:”设置为 NO,那么我的主页上的链接可以正常工作,但是请参阅显示正确页面的页面 http://localhost/magento/index.php/foo.html,但是该网站的作品我不喜欢这个网址。我希望它是 http://localhost/magento/foo.html 没有 index.php 位,因为这也可能对 SEO 更友好。

谢谢,

约翰·戈切


更新:我尝试取消注释 ubuntu 放入 /etc/hosts 的人工 127.0.1.1 IP 地址并将其放置为我的真实 IP,但没有运气。我仍然有完全相同的问题。并且我的浏览器中的 URL 被重写为 http://localhost / 等...每当我在其中输入 192.168.3.31、avalanche 或 avalanche.com 时。我仍在试图弄清楚如何解决上述问题,因为这并没有做到。

127.0.0.1       localhost
#127.0.1.1      avalanche

192.168.4.35    avalanche avalanche.com

当我重新启动 Apache 时,我得到:

# service apache2 restart
 * Restarting web server apache2                                                apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.4.35 for ServerName
 ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.4.35 for ServerName

不知道如何解决原始问题。我正在本地服务器上进行测试。


我什至尝试过这个解决方案,然后重新启动 apache2,但没有运气!

如何从 URL 中删除 index.php?

所以放置:

RewriteEngine On
RewriteBase /mymagento/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

不起作用,即使使用 RewriteBase /,它也不起作用。


好的,最后我设法解决了问题。文件 /etc/apache2/sites-enabled/000-default 为该文件中定义的所有目录设置了以下指令:

 AllowOverride None

例如,对于 /var/www 这是 Ubuntu 12.04 LTS Linux 系统上设置的默认文档根目录,此文件包含

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

据我了解,这意味着在此目录及其所有子目录中找到的 .htaccess 文件将不会被解析。要解决此问题,设置以下内容就足够了:

AllowOverride All

这意味着您将能够覆盖 /etc/apache2/apache2.conf(或其中包含的 /etc/apache2/httpd.conf)中的服务器配置指令。

AllowOverride 默认设置为 None 的原因之一可能是它减慢了服务器的速度,另一个是出于安全原因。该指令应设置在标签内,后者可以覆盖前者。默认情况下未设置的另一个原因是,每次加载目录路径中的文件时必须在站点上递归解析 .htaccess 会减慢系统速度,从而将 .htaccess 内容放在 /etc/apache2/httpd.conf尽可能推荐,因为它可以提高速度。

所以放置

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            #AllowOverride None
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

在 /etc/apache2/sites-enabled/000-default 里面

并运行: service apache2 restart

是解决方案。

4

7 回答 7

20

你试过了吗:

RewriteBase /magento/

而不是 RewriteBase /mymagento/ 因为你的网址是 http://localhost/magento/

您的 apache 虚拟主机是否允许覆盖配置,例如

<VirtualHost *:80>
...
<Directory /var/www/magento/>
    AllowOverride All
</Directory>
</VirtualHost>
于 2012-07-29T09:42:23.863 回答
4

您的 Magento 根目录中是否有适当的 .htaccess 文件?此外,您可能会遇到localhost. 建议使用 127.0.0.1 或在主机文件中映射开发域。

于 2012-07-28T16:52:26.690 回答
3

在 Magento 配置中(通过系统 > 配置在 Magento 管理面板中访问)有一些相关设置决定了最终的搜索引擎友好 URL 的样子。

Web > Search Engine Optimization > Use Web Server Rewrites

应始终打开的设置。如果不是 "/index.php/" 将被添加到 URL 中,这是不必要的并且看起来很丑陋。要启用此选项,您还需要在托管环境中启用 Apache mod_rewrite

Catalog > Search Engine Optimizations > Product URL Suffix

此处的默认值为“.html”,它将附加到每个产品 URL。一些 SEO 专家声称这是提高评级所必需的,而其他 SEO 出口商则表示并非如此。对于我们与 Joomla 的 MageBridge 集成!此设置必须为空。

Catalog > Search Engine Optimizations > Category URL Suffix

同上,但现在是分类。

Catalog > Search Engine Optimizations > Use categories path for product URLs

启用此选项后,产品 URL 还将包括类别 URL 键。虽然可以说这会导致重复的内容,但产品页面也可能会从中受益,因为它们成为更大结构的一部分。

Catalog > Search Engine Optimizations > Use Canonical Link Meta Tag For Products

如果您真的担心重复内容(这并不像某些人告诉您的那么糟糕),那么您可以启用规范标签,一旦检测到重复内容,该标签会告诉搜索引擎哪个页面处于领先地位。

Catalog > Search Engine Optimizations > Use Canonical Link Meta Tag For Categories

与上述相同,但针对类别。

关于此事的进一步阅读http://www.yireo.com/tutorials/magento/magento-administration/664-fixing-url-rewrites-with-magento

于 2012-07-29T10:24:38.583 回答
3

为 wamp 启用 Apache 重写模块对我有用。

在此处输入图像描述

于 2014-04-14T05:28:14.343 回答
3
Go to admin url of your site. 
Suppose,http://example.com/index.php/admin/

Go to 'System' menu from navigation and click on 'Configuration'.
Under the 'General' tab in the left, click on 'Web'.
Open the 'Search Engines Optimization' section by clicking on it.
Then set 'Use Web Server Rewrites' value to 'No'
于 2014-08-28T10:08:19.337 回答
2

这是一个mod_rewrite问题。我正在运行Ubuntu,并且在为商店迁移设置 apache 和 magento 时遇到了同样的问题。

更改/etc/apache2/sites-available/000-default.conf为包含

<VirtualHost ...>
...
<Directory /var/www>
    Options Indexes FollowSymLinks MultiViews   
    AllowOverride All
    Order allow,deny
    allow from all 
</Directory>

</VirtualHost>

因此允许在网络服务器上重写。var/www

为了让 apache 处理来自 magentos 的重写规则。htaccess文件,通过
启用重写模块

sudo a2enmod rewrite

并通过重启 apache

sudo /etc/init.d/apache2 force-reload 
//(not service apache2 restart)

为我解决了整个问题。

请参阅http://wiki.ubuntuusers.de/Apache/mod_rewrite
http://wiki.ubuntuusers.de/Apache以获取有关如何正确设置的详细说明。

于 2014-04-03T10:59:32.920 回答
1

将我的实时站点转移到本地主机时,我遇到了同样的问题。最后我解决了。

我有 Windows 操作系统。所以我为我的本地主机使用了 WAMP 堆栈。我花了很多时间通过更改 .htaccess 文件、修改 DB 中的 core_config_data 表来检索本地主机中的所有 URL 及其内容,但一切都出错了。

最后我得到了在 Apache 服务器中启用 rewrite_module 的线索。1. 启用它 单击托盘栏中的 Wamp 图标(WAMP->Apache->Apache 模块-> 并选择 rewrite_module)。2. 重启 Wamp 服务器。3.清除缓存(我认为可选) - 删除 var/cache 文件夹中的所有文件

确保您的根文件夹中有 .htaccess 文件让我们假设(localhost/magento/.htaccess)。如果你没有,你将不会得到结果。

就是这样。

我希望现在您能够检索除主页以外的所有其他页面和 URL,并且您也不会收到 404 错误页面。

于 2013-07-08T11:38:34.920 回答