【发布时间】:2017-06-04 19:58:14
【问题描述】:
我的 Magento 网站上有 http://magento.store/about 和 http://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