Redirect .myshopify.com to Custom Domain: Ultimate Guide with Developer Exception
Redirect .myshopify.com to custom domain is essential for Shopify store owners who want to maintain brand consistency, improve SEO rankings, and provide a seamless shopping experience. In this ultimate guide, you will learn how to redirect .myshopify.com to custom domain properly, including how to set up a developer exception using cookies for easy access during testing.
Why Redirect .myshopify.com to Custom Domain?
Redirecting .myshopify.com
to your custom domain is crucial because:
- Brand Consistency: A custom domain reinforces your brand identity and builds trust.
- SEO Benefits: Redirecting helps consolidate SEO value and avoid duplicate content penalties.
- Better User Experience: Customers find custom domains easier to remember and trust.
- Marketing Consistency: Simplifies advertising and social media sharing.
Without redirection, visitors landing on .myshopify.com
can cause confusion and dilute your store’s SEO strength.
How to Redirect .myshopify.com to Custom Domain
Shopify automatically redirects to your primary domain if set up correctly. But for development or testing stores without a custom domain assigned, manual redirect is necessary.
Add this JavaScript snippet to your Shopify theme’s theme.liquid
file to redirect visitors from .myshopify.com
to your custom domain:
{% raw %}
{% if request.host contains 'myshopify.com' %}
<script>
if (!window.location.search.includes('dev=true')) {
window.location.href = "https://www.yourcustomdomain.com";
}
</script>
{% endif %}
{% endraw %}
This snippet ensures visitors are redirected to your custom domain unless the URL contains ?dev=true
, which is used to create a developer exception.
Developer Exception Using Cookie
To allow developers to access the Shopify dev store without redirect loops, use a cookie-based exception. When visiting the store with ?dev=true
in the URL, a cookie is set in the browser to bypass redirects on future visits.
Code to add inside your theme.liquid
:
{% raw %}
{% if request.host contains 'myshopify.com' %}
<script>
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('dev') === 'true') {
document.cookie = "shopify_dev=true; path=/";
window.history.replaceState(null, "", window.location.pathname);
}
function getCookie(name) {
const value = "; " + document.cookie;
const parts = value.split("; " + name + "=");
if (parts.length === 2) return parts.pop().split(";").shift();
}
if (!getCookie("shopify_dev")) {
window.location.href = "https://www.yourcustomdomain.com";
}
</script>
{% endif %}
{% endraw %}
This setup ensures all visitors get redirected except developers who use ?dev=true
once to set a cookie.
SEO Tips for Redirecting .myshopify.com to Custom Domain
Redirecting .myshopify.com
to your custom domain benefits your SEO by:
- Using 301 Redirects: Shopify’s server-side 301 redirects are best; JavaScript redirects are fallback.
- Canonical URLs: Set canonical tags to point to your custom domain.
- Consistent Linking: Internal and external links should use your custom domain.
- Monitor Redirects: Use tools like Google’s Redirect Guidelines and HTTP Status Checker.
Frequently Asked Questions
Can I disable .myshopify.com completely?
No, Shopify requires every store to have a .myshopify.com domain. However, you can hide or redirect it for visitors.
How long does the developer cookie last?
The cookie remains until cleared by the user or browser. You can customize expiration if needed.
Is this redirect method SEO friendly?
Yes, redirecting .myshopify.com to your custom domain helps avoid duplicate content and improves SEO consolidation.
Can multiple developers use this method?
Yes, any developer who visits with ?dev=true
will set the cookie and bypass redirects on future visits.
Final Thoughts
Understanding how to redirect .myshopify.com to custom domain ensures your Shopify store presents a professional image and consolidates SEO strength. The cookie-based developer exception balances user redirection with seamless developer access during testing.
Please use this method at your own risk. If you are unsure or need assistance, feel free to contact us anytime for expert Shopify development and SEO support.
Explore Shopify’s official domain management documentation and Google’s redirect best practices for more info.