Question

I have rules in my .htaccess file that I use in order to completely eliminate index.php from all URLs in a Magento installation I have (currently in a subdomain).

    Options +FollowSymLinks
    RewriteEngine on

    RewriteBase /

    RewriteCond %{THE_REQUEST} ^.*/index.php
    RewriteRule ^(.*)index.php$ http://my.website.com/$1 [R=301,L]
    #RewriteRule ^index.php/(.*) $1 [R=301,QSA,L]

Everything works fine (almost). Whenever I type in a URL with index.php it automatically redirects to its non index.php version. The commented line (RewriteRule ^index.php/(.*) $1 [R=301,QSA,L]) is the one that's giving me trouble. When uncommented, I can't save any changes in the backend (Ex: Changing the store name or a product name, etc...)

What am I doing wrong?

Was it helpful?

Solution

Thanks for your help. I figured it out. To backtrack, I believe the options in Magento remove index.php visually, however the website still responds to it, if I were to type in www.mysite.com/index.php for example the home page will still load. I never want to see index.php anywhere, so I'd like to redirect any URLs with index.php to it's non index.php version. So I've come up with the following:

RewriteRule ^(.*)(index.php/admin)($|/) - [L]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.mysite.com/$1 [R=301,L]
RewriteRule ^index.php/(.*) $1 [R=301,QSA,L]

The issue I was having was that I was also redirecting index.php URLs in the backend, therefore no changes were being saved. The first line above ommits the admin (backend) from redirects and all URLs with index.php redirect (301) to its non index.php version correctly.

OTHER TIPS

What is this? This rule shouldn't be in your htaccess:

RewriteRule ^(.*)index.php$ http://my.website.com/$1 [R=301,L]

I'm not sure what you're trying to accomplish here - seems like it's not well-formed, as it's logically saying:

If you see a file named index.php, which has any number of required characters before it, and that's all there is to the URI, then redirect to my.website.com and append whatever was before the index.php part to the end (even if it results in a double-slash). Oh, and this is the very last rule. Ignore whatever happens next.

I don't think that's what you want to happen. I think you're trying to avoid SEO canonicalization issues. Rather than redirecting, use the canonical link meta tag in System > Config > Catalog > SEO

In the future, don't modify your htaccess. Pull down a fresh one and re-install it from here:

http://svn.magentocommerce.com/source/branches/1.7/.htaccess

After you do that, check your httpd.conf file and ensure that AllowOverride is set to All.

To remove index.php from your URI, navigate to System > Config > Web > Search Engine Optimization and change Use Web Server Rewrites to 'yes'.

If that fails to save (doubtful) check the following:

  • Ensure the db user assigned to Magento has write access to core_config_data and catalog* tables. Or all tables, for that matter.
  • Kick off the install process again by deleting app/etc/local.xml
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top