【问题标题】:How to remove index.php in Magento 1.9 using .htaccess如何使用 .htaccess 在 Magento 1.9 中删除 index.php
【发布时间】:2017-06-04 19:58:14
【问题描述】:

我的 Magento 网站上有 http://magento.store/abouthttp://magento.store/index.php/about 这样的 URL。我不需要这两页,我需要在 .htaccess 文件中正确重写它们。我已经尝试了在 StackOverflow 上可以找到的所有内容,但没有任何帮助。我使用 adpanel 在配置中配置了 URL 重写,使用了不同的解决方案,但最重要的是,我要做这些重定向,但我的 adpanel 没有将任何更改写入网站的数据库(我使用了这个解决方案:

RedirectMatch 301 ^/index.php/((?!admin).*) http://www.magento.store/$1

在这种情况下,无法更改 adpanel 中的任何内容。常用的解决方案如

RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

也不行。据我了解,它们被忽略了。 我该如何解决这个问题?

这是我的 .htaccess 文件(关于 mod_rewrite 的部分):

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^magento\.store$ [NC]
RewriteRule ^(.*)$ http://www.magento.store/$1 [L,R=301]
# redirect pagination
RewriteCond %{QUERY_STRING} ^p=1$
RewriteRule ^(.+)$ http://www.magento.store/$1? [R=301,L]
RewriteRule ^pagename$ http://www.magento.store/page-name [L,R=301]

#RewriteCond %{REQUEST_URI} !/admin/
#RewriteRule ^index\.php/(.+)$ /$1 [R,L]
#RewriteRule ^index\.php/?$ / [R,L]
#RedirectMatch 301 ^/index.php/(.*)$ /$1
#RedirectMatch 301 ^/index.php/((?!admin).*) http://magento.store/$1

RewriteRule ^api/rest api.php?type=rest [QSA,L]
############################################
## workaround for HTTP authorization
## in CGI environment

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

############################################
## TRACE and TRACK HTTP methods disabled to prevent XSS attacks

RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]

############################################
## always send 404 on missing files in these folders

RewriteCond %{REQUEST_URI} !^/(media|skin|js)/

############################################
## never rewrite for existing files, directories and links

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

############################################
## rewrite everything else to index.php

RewriteRule .* index.php [L]

</IfModule>

我的文件中是否可能存在一些冲突?

【问题讨论】:

  • 尝试使用 magento 的默认 htaccess。
  • @urfusion 很遗憾,但我无法做到这一点,因为这些配置已经在生产服务器上使用并且由以前的开发人员编写。我不能使用默认值。

标签: .htaccess magento redirect mod-rewrite url-rewriting


【解决方案1】:

谢谢大家的帮助。最后,我提出了解决方案,如下:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !/adpanel/
RewriteRule ^index\.php/(.*)$ http://magento.store/$1 [L,R=301]

【讨论】:

    【解决方案2】:

    使用下面的 .htaccess 规则:

    ## index.php on default domain
    RewriteCond %{THE_REQUEST} ^.*/index.php
    RewriteCond %{REQUEST_URI} !^/downloader.*$
    RewriteRule ^(.*)index.php$ http://www.idesignmydrapes.com [R=301,L]
    RewriteCond %{HTTP_HOST} ^idesignmydrapes\.com$ [NC]
    

    【讨论】:

      【解决方案3】:

      您可以捕获 index.php 之后的部分并使用重定向客户端

      RewriteEngine on
      RewriteRule ^index\.php/(.+)$ /$1 [R,L]
      RewriteRule ^index\.php/?$ / [R,L]
      

      这会将所有以 index.php/ 开头的请求重定向到没有 index.php 的 URL。此外 index.php 和 index.php/ 被重定向到主页。

      【讨论】:

      猜你喜欢
      • 2012-01-17
      • 2013-05-15
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      • 2021-10-02
      • 2015-01-20
      相关资源
      最近更新 更多