Redirecting Magento Installation Path from Subfolder to Main Domain Name
You’ve installed your Magento store in a subdirectory (mydomain.com/mag) for testing purposes, which is a good practice to avoid overwriting critical files under the public_html directory. However, you want your live website to be accessible directly via mydomain.com. Let’s walk through how to achieve this without affecting your SEO.
Understanding the Issue
When Magento is installed in a subdirectory, it sets the base URL for the store accordingly. This means that all internal and external links generated by Magento will include the /mag path. To redirect visitors from mydomain.com/mag to mydomain.com, we need to update this base URL.
Rewriting the Base URLs
-
Database Update: First, let’s update the base URLs in the database. Log into your MySQL database using a tool like phpMyAdmin or your hosting control panel. Find the
core_config_datatable and locate the following records:web/unsecure/base_urlweb/secure/base_url
Update these values from
http://mydomain.com/mag/tohttp://mydomain.com/. Save your changes. -
Magento Configuration: Next, we need to update the base URLs in the Magento configuration files:
a. Open the
app/etc/local.xmlfile and locate the<config>tag.b. Change:
<base_url>http://mydomain.com/mag/</base_url> <secure_base_url>https://mydomain.com/mag/</secure_base_url>To:
<base_url>http://mydomain.com/</base_url> <secure_base_url>https://mydomain.com/</secure_base_url>c. Save the file.
-
Renaming the Subfolder: Now, we need to rename or delete the
magfolder in yourpublic_htmldirectory. This will not affect the Magento installation as we’ve already updated the database and configuration files. You can do this via your FTP client or through the hosting control panel’s file manager.
SEO Considerations
Redirecting from a subfolder to the root domain is actually beneficial for SEO:
- It consolidates all of your website’s authority into one domain.
- It makes it easier for search engines to understand and index your site structure.
- It allows you to use a single sitemap file.
However, if you’ve already built links pointing to mydomain.com/mag, they will now be redirecting 1:1. To mitigate this, consider setting up 301 redirects or using the canonical tag in your .htaccess file.
Conclusion
By following these steps, you should now be able to access your live Magento website directly via mydomain.com without affecting your SEO efforts. This approach is much safer than installing directly into the root directory, as it allows for easy testing and rollback if needed.
Remember to test your site thoroughly after making these changes to ensure all internal and external links are working correctly. If you encounter any issues, feel free to explore our guide on Magento Troubleshooting for further assistance.
Happy coding!