【发布时间】:2012-07-27 00:16:59
【问题描述】:
我的 magento 安装在 Ubuntu Linux 的 /var/www/magento 下。 这个问题看起来像档案中的一些问题 但实际上有些不同。当我安装 Magento 时 Ubuntu Linux 我启用了 Apache mod_rewrite URL 重写。
当我访问 http://localhost/magento 我的服务器将 URL 重写为 http://localhost/magento/ 并显示页面。然后我点击其中一个链接 在导航栏中,假设它是导航栏项目“foo”。 然后magento带我去:
http://localhost/magento/foo.html
显示“未找到”的 apache 页面。
我要把网址改成----->
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 更友好。
谢谢,
约翰·戈奇
更新:我尝试取消注释我的人工 127.0.1.1 IP 地址 哪个 ubuntu 已放入 /etc/hosts 并将其放置在我的真实 IP 中,但是 没有运气。我仍然有完全相同的问题。还有里面的网址 我的浏览器被重写为 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,但没有运气!
How to remove index.php from URLs?
所以放置:
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 每次目录路径中的文件 加载可以减慢系统,从而放置 /etc/apache2/httpd.conf 中的 .htaccess 内容 可能是值得推荐的,因为它可能导致 提高速度。
所以放
<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
是解决方案。
【问题讨论】:
-
我已经尝试了所有我能找到的解决方案,它们完全没有区别,即使我在管理面板中启用 mod_rewrite,清除缓存,重新启动 apache,并将代码放在 /var /www/mymagento/.htaccess (并转到 http://myip/mymagento/admin 这给出了文件未找到而 http://myip/mymagento/index.php/admin 工作)。
-
如果您已设法解决问题,请不要将其添加到您的问题中。而是将其作为单独的答案。允许并鼓励您这样做。
标签: templates magento url-rewriting