2013-03-18 140 views
1

我在我的共享主机服务器上安装了Magento。我已经在magento管理面板中做了所有必要的更改。所有的网址都很好。但唯一的问题是,我可以访问应用商店我的产品:将index.php重定向到.htaccess中的根目录

http://mydomain.com/category/product.html并与http://mydomain.com/index.php/category/product.html

所以我想知道怎样才能摆脱的index.php。我想重定向由index.php组成的url到没有index.php的网址

在发布之前,我检查了magento论坛,并在stackoverflow上搜索,但没有找到任何成功。

回答

6

可以index.php后捕获一部分,并与

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

客户端重定向这会将所有请求开始index.php/的URL没有index.php。另外index.phpindex.php/被重定向到主页。

更新

要排除管理区,必须在第一条规则前插入一个附加RewriteCond

RewriteCond %{REQUEST_URI} !/admin/ 

总之给人

RewriteEngine on 
RewriteCond %{REQUEST_URI} !/admin/ 
RewriteRule ^index\.php/(.+)$ /$1 [R,L] 
RewriteRule ^index\.php/?$/[R,L] 
+0

完美!这帮助我。但主页没有重定向。除了一切正常。我用这个重定向主页http://sourcelibrary.org/2011/06/01/redirecting-index-php-to-root-using-htaccess/ – SpiritOfDragon 2013-03-18 17:45:16

+0

@ user1395787我添加了一个规则来重定向普通的'index.php'主页。 – 2013-03-18 18:11:43

+0

你好,我已经在我的.htaccess中使用了上面的代码,但是当我尝试在我的magento管理控制面板中保存任何东西时,没有任何东西被保存。但是,当我试图从htaccess文件中删除最后2行时,它的效果很好。你能告诉我为什么吗? – SpiritOfDragon 2013-03-22 11:12:12

3

如果您想删除index.php来自您网站上的所有链接,这个解决方案实际上对我来说最合适:

RedirectMatch 301 /index.php/(.*) http://www.yourdomain.com/$1 

来源:http://www.lionseo.com/blog/htaccess-redirect-301/

+1

这适用于我,但如何逃脱管理网址或每次重定向? – AjmeraInfo 2016-03-29 23:14:26

+1

这将跳过管理网址:'RedirectMatch 301 ^/index.php /((?! admin)。*)$/$ 1'。此外,域名不是必需的。 – Andrea 2016-06-28 09:24:49

相关问题