2013-03-18 64 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

相關問題