Mr Benn
Mr Benn

Reputation: 476

Changing Magento domain breaks URL rewrites

I'm just launching my first Magento store (on CentOS & Apache) and I've switched over from my setup subdomain - http://prelive.mydomain.com (where everything worked fine, with url rewriting enabled & working) - to the live subdomain http://www.mydomain.com, basically just by doing the following:

  1. clearing caches via the admin interface
  2. updating the secure & unsecure base urls in the db
  3. moving the entire site file system from /var/www/html/prelive to /var/www/html/www (I tried copying but it caused all sorts of permission problems which I'll figure out later!)
  4. manually editing the media base path in var/resource_config.json
  5. updating my virtual host like this:

    <VirtualHost *:80>
        DocumentRoot /var/www/html/www
        ServerName www.mydomain.co.uk
        ServerAlias www.mydomain.co.uk
        ErrorLog logs/www.mydomain.co.uk-error_log
    </VirtualHost>
    
  6. editing the base .htaccess file like this ()

    SetEnvIf Host www\.mydomain.co.uk MAGE_RUN_CODE=angling_r_en
    SetEnvIf Host www\.mydomain.co.uk MAGE_RUN_TYPE=store
    SetEnvIf Host ^mydomain.co.uk MAGE_RUN_CODE=angling_r_en
    SetEnvIf Host ^.mydomain.co.uk MAGE_RUN_TYPE=store
    

And it almost works... but the url rewriting is broken. I can see the site on http://www.mydomain.com but navigating to subpages gets a 404 (e.g. http://www.mydomain.com/path/to/product.html ), unless I specifically alter the URL to point through index.php like this http://www.mydomain.com/index.php/path/to/product.html or http://www.mydomain.com/index.php/admin

For reference, in .htaccess I also have (left unchanged during the switch of subdomain):

RewriteBase /

and

RewriteRule .* index.php [L]

Any thoughts on what I forgot?

Many thanks Ben

Upvotes: 0

Views: 1480

Answers (2)

Mr Benn
Mr Benn

Reputation: 476

Ok - so the problem was on the server all along, not Magento...

Basically rewrites weren't working because I needed this in both my VirtualHost container in both both httpd.conf and ssl.conf:

<Directory /var/www/html/www>
        AllowOverride All
</Directory>

What I still don't understand is how it worked on the old location (which definitely didn't have this) and not the new one... but it works just the same as before now, with "Use Web Server Rewrites" turned on in System > Configuration > Web, creating "clean" urls which are rewritten through index.php by mod_rewrite.

Upvotes: 1

1000Nettles
1000Nettles

Reputation: 2334

Most likely you need to reindex the catalog URL rewrites to incorporate your new URL changes! See System > Index Management and reindex the Catalog URL Rewrites.

Upvotes: 1

Related Questions