没有index.php,除主页之外的Magento URL不起作用

时间:2012-07-28 16:24:36

标签: templates magento url-rewriting

我的magento安装在/ var / www / magento下的Ubuntu Linux上。 这个问题看起来像档案中的一些问题 但实际上有些不同。当我安装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工作中有些不对劲。

谢谢,

John Goche

配置:系统 - >配置 - > (一般 - >)网址:

使用Web服务器重写:是

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

如果我将“User Web Server Rewrites:”设置为NO,则表示链接 从我的主页工作正常,但看到页面 http:// localhost / magento / index.php / foo.html 它显示正确的页面,但是 网站的作品我不喜欢这个网址。一世 希望它是http:// localhost / magento / foo.html 没有index.php位,因为这也可能 对SEO更友好。

谢谢,

John Goche


更新:我已经尝试取消注释我的人工127.0.1.1 IP地址 ubuntu放入/ etc / hosts并放置我真正的IP但是 没运气。我仍然有完全相同的问题。和里面的URL 我的浏览器被重写为http:// localhost / etc ...当我 在其中键入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 每次目录路径中的文件时,跨站点 加载可以减慢系统,从而放置 .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

是解决方案。

7 个答案:

答案 0 :(得分:19)

你有没有尝试过:

RewriteBase /magento/

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

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

<VirtualHost *:80>
...
<Directory /var/www/magento/>
    AllowOverride All
</Directory>
</VirtualHost>

答案 1 :(得分:4)

你的Magento根目录中有the appropriate .htaccess file吗?此外,您可能会遇到localhost的问题。建议使用127.0.0.1或在主机文件中映射开发域。

答案 2 :(得分:3)

在Magento配置中(通过系统&gt;配置在Magento管理面板中访问),有一些相关设置可确定最终搜索引擎友好URL的外观。

Web > Search Engine Optimization > Use Web Server Rewrites

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

Catalog > Search Engine Optimizations > Product URL Suffix

此处的默认值为&#34; .html&#34;它将附加到每个产品URL。一些SEO专家声称这需要更好的评级,其他SEO出口说它不是。我们的MageBridge与Joomla集成!此设置必须为空。

Catalog > Search Engine Optimizations > Category URL Suffix

与上述相同,但现在是类别。

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

启用此选项后,产品网址还会包含类别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

答案 3 :(得分:3)

为wamp启用Apache重写模块为我工作。

enter image description here

答案 4 :(得分: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'

答案 5 :(得分:1)

将我的实时网站转移到localhost时遇到了同样的问题。最后我解决了。

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

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

确保您在根文件夹中有.htaccess文件假设(localhost / magento / .htaccess)。如果你没有,你将无法得到结果。

多数民众赞成。

我希望你现在能够检索除家之外的所有其他页面和网址,而且你也不会得到404错误页面。

答案 6 :(得分:1)

这是一个 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 file(s),
通过

启用重写模块
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详细解释了如何以正确的方式设置。