我的 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,但没有运气!
所以放置:
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
是解决方案。