• BBgmoro

        See all notifications

        Skip to content
        Moz logo Menu open Menu close
        • Products
          • Moz Pro
          • Moz Pro Home
          • Moz Local
          • Moz Local Home
          • STAT
          • Moz API
          • Moz API Home
          • Compare SEO Products
          • Moz Data
        • Free SEO Tools
          • Domain Analysis
          • Keyword Explorer
          • Link Explorer
          • Competitive Research
          • MozBar
          • More Free SEO Tools
        • Learn SEO
          • Beginner's Guide to SEO
          • SEO Learning Center
          • Moz Academy
          • MozCon
          • Webinars, Whitepapers, & Guides
        • Blog
        • Why Moz
          • Digital Marketers
          • Agency Solutions
          • Enterprise Solutions
          • Small Business Solutions
          • The Moz Story
          • New Releases
        • Log in
        • Log out
        • Products
          • Moz Pro

            Your all-in-one suite of SEO essentials.

          • Moz Local

            Raise your local SEO visibility with complete local SEO management.

          • STAT

            SERP tracking and analytics for enterprise SEO experts.

          • Moz API

            Power your SEO with our index of over 44 trillion links.

          • Compare SEO Products

            See which Moz SEO solution best meets your business needs.

          • Moz Data

            Power your SEO strategy & AI models with custom data solutions.

          Turn SEO data into actionable content briefs

          Turn SEO data into actionable content briefs

          Learn more
        • Free SEO Tools
          • Domain Analysis

            Get top competitive SEO metrics like DA, top pages and more.

          • Keyword Explorer

            Find traffic-driving keywords with our 1.25 billion+ keyword index.

          • Link Explorer

            Explore over 40 trillion links for powerful backlink data.

          • Competitive Research

            Uncover valuable insights on your organic search competitors.

          • MozBar

            See top SEO metrics for free as you browse the web.

          • More Free SEO Tools

            Explore all the free SEO tools Moz has to offer.

          Let your business shine with Listings AI

          Let your business shine with Listings AI

          Get found
        • Learn SEO
          • Beginner's Guide to SEO

            The #1 most popular introduction to SEO, trusted by millions.

          • SEO Learning Center

            Broaden your knowledge with SEO resources for all skill levels.

          • On-Demand Webinars

            Learn modern SEO best practices from industry experts.

          • How-To Guides

            Step-by-step guides to search success from the authority on SEO.

          • Moz Academy

            Upskill and get certified with on-demand courses & certifications.

          • MozCon

            Save on Early Bird tickets and join us in London or New York City

          Access 20 years of data with flexible pricing
          Moz API

          Access 20 years of data with flexible pricing

          Find your plan
        • Blog
        • Why Moz
          • Digital Marketers

            Simplify SEO tasks to save time and grow your traffic.

          • Small Business Solutions

            Uncover insights to make smarter marketing decisions in less time.

          • Agency Solutions

            Earn & keep valuable clients with unparalleled data & insights.

          • Enterprise Solutions

            Gain a competitive edge in the ever-changing world of search.

          • The Moz Story

            Moz was the first & remains the most trusted SEO company.

          • New Releases

            Get the scoop on the latest and greatest from Moz.

          Surface actionable competitive intel
          New Feature

          Surface actionable competitive intel

          Learn More
        • Log in
          • Moz Pro
          • Moz Local
          • Moz Local Dashboard
          • Moz API
          • Moz API Dashboard
          • Moz Academy
        • Avatar
          • Moz Home
          • Notifications
          • Account & Billing
          • Manage Users
          • Community Profile
          • My Q&A
          • My Videos
          • Log Out

        The Moz Q&A Forum

        • Forum
        • Questions
        • My Q&A
        • Users
        • Ask the Community

        Welcome to the Q&A Forum

        Browse the forum for helpful insights and fresh discussions about all things SEO.

        1. Home
        2. SEO Tactics
        3. On-Page Optimization
        4. How do I carry out a redirect? Is there a code I need to use?

        Moz Q&A is closed.

        After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.

        How do I carry out a redirect? Is there a code I need to use?

        On-Page Optimization
        redirect redirect chain
        15
        16
        708
        Loading More Posts
        • Watching

          Notify me of new replies.
          Show question in unread.

        • Not Watching

          Do not notify me of new replies.
          Show question in unread if category is not ignored.

        • Ignoring

          Do not notify me of new replies.
          Do not show question in unread.

        • Oldest to Newest
        • Newest to Oldest
        • Most Votes
        Reply
        • Reply as question
        Locked
        This topic has been deleted. Only users with question management privileges can see it.
        • laurentjb
          laurentjb Subscriber last edited by

          How do I carry out a redirect? Is there a code I need to use? Thank you in advance.

          hughcollins Shahreez BacklinkDigital raobilal6 4 Replies Last reply Reply Quote 0
          • UlkePulke
            UlkePulke @meltingpointgoat last edited by

            @meltingpointgoat maybe I can recommend the following for whats its worth,

            I’ve been diving deep into SEO recently and found a bunch of tools that have been super helpful for different aspects of my workflow. Thought I’d share a few in case you find them useful!

            https://ralfvanveen.com/en/tools/domain-age-checker/
            https://ralfvanveen.com/en/tools/domain-authority-checker/
            https://ralfvanveen.com/en/tools/seo-impact-calculator/
            https://ralfvanveen.com/en/tools/content-length-vs-ranking-calculator/
            https://ralfvanveen.com/en/tools/content-security-policy-csp-checker/
            https://ralfvanveen.com/en/tools/backlink-outreach-email-generator/
            https://ralfvanveen.com/en/tools/fetch-and-render/
            https://ralfvanveen.com/en/tools/bulk-pagespeed-checker/
            https://ralfvanveen.com/en/tools/bulk-amp-validator/
            https://ralfvanveen.com/en/tools/xml-sitemap-checker/
            https://ralfvanveen.com/en/tools/schema-markup-generator/

            I’ve found these tools over at https://ralfvanveen.com/en/tools/. Thought they were worth sharing!

            Are you using similar tools? Would love to know what’s been working for you lately.
            Please let me know, I am regularly looking for new ways to optimize my SEO strategies.

            Regards,

            Ulrich

            1 Reply Last reply Reply Quote 0
            • raobilal6
              raobilal6 @laurentjb last edited by

              Hi!
              nice comment

              1 Reply Last reply Reply Quote 0
              • meltingpointgoat
                meltingpointgoat last edited by

                Redirecting sounds simple, but it can be a lot of work, especially for SEO. You need to carefully map old URLs to new ones, or you risk losing traffic. Big companies often have dedicated teams managing this to ensure everything’s smooth. Implementing strategies like resource smoothing helps here - spreading out tasks over time so no one is overwhelmed and SEO remains on point (see here).

                For example, you could have one team member focus on identifying which URLs need redirecting while another handles updating the code over a week, instead of doing everything at once. This way, the workload stays manageable, and there’s less risk of making mistakes.

                When implementing redirects, always check for broken links and monitor the changes to ensure traffic isn’t dropping. And remember, a good redirect strategy is essential for maintaining SEO, so take your time and do it right to avoid losing valuable rankings.

                UlkePulke 1 Reply Last reply Reply Quote 0
                • jhk2021
                  jhk2021 last edited by

                  To carry out a redirect, you can use the following code depending on the language or platform you're working with.
                  In HTML (meta tag redirect):

                  <meta http-equiv="refresh" content="0; url=https://new-url.com">
                  
                  

                  In JavaScript:

                  window.location.href = "https://new-url.com";
                  

                  In PHP:

                  header("Location: https://new-url.com");
                  exit();
                  

                  Choose the appropriate method based on your environment.

                  Thanks!
                  JHK Infotech

                  1 Reply Last reply Reply Quote 0
                  • BacklinkDigital
                    BacklinkDigital @laurentjb last edited by

                    @laurentjb ... Depend on your goals, if you are using cloudflare, you can go to page rules and create 301 / 302 redirect easily

                    1 Reply Last reply Reply Quote 0
                    • BacklinkDigital
                      BacklinkDigital last edited by

                      @laurentjb

                      Depend on your goals, if you are using cloudflare, you can go to page rules and create 301 / 302 redirect easily

                      1 Reply Last reply Reply Quote 0
                      • shob0000
                        shob0000 last edited by

                        @laurentjb said in How do I carry out a redirect? Is there a code I need to use?:

                        How do I carry out a redirect? Is there a code I need to use? Thank you in advance.
                        To carry out a redirect, you typically use a piece of code specific to the platform you're working on. For example, in HTML, you can use <meta http-equiv="refresh" content="0;url=http://example.com">. If you’re using server-side code, such as PHP, you can use header("Location: http://example.com");. Just like how you might tweak a Wendy’s Taco Salad recipe to fit your taste, adjusting redirect code ensures your users are sent to the right place. i have wendy's taco salads related site and same done for that website too

                        1 Reply Last reply Reply Quote 0
                        • shtefcs
                          shtefcs last edited by

                          If you are using free CloudFlare DNS and SSL, you can create 301 redirection easily with their tools.

                          1 Reply Last reply Reply Quote 0
                          • jahangir43
                            jahangir43 last edited by

                            Yes, i have done many site like Digitech Journals. To carry out a redirect, you need to use specific code depending on the type of redirect and the server environment you’re working with. The most common types of redirects are 301 (permanent) and 302 (temporary) redirects.

                            1. Using .htaccess (Apache Server)

                            If your website is hosted on an Apache server, you can use the .htaccess file to create redirects.

                            a. 301 Permanent Redirect:

                            Redirect 301 /old-page.html https://www.example.com/new-page.html
                            
                            • Explanation: This code permanently redirects old-page.html to new-page.html.

                            b. 302 Temporary Redirect:

                            Redirect 302 /old-page.html https://www.example.com/new-page.html
                            
                            • Explanation: This code temporarily redirects old-page.html to new-page.html.

                            c. Redirecting an Entire Domain:

                            Redirect 301 / https://www.newdomain.com/
                            
                            • Explanation: This code permanently redirects all pages from the old domain to the new domain.

                            2. Using PHP for Redirects

                            If you have access to your website’s PHP code, you can use the following PHP code for redirects.

                            a. 301 Permanent Redirect:

                            <?php
                            header("HTTP/1.1 301 Moved Permanently");
                            header("Location: https://www.example.com/new-page.html");
                            exit();
                            ?>
                            
                            • Explanation: This PHP code permanently redirects to new-page.html.

                            b. 302 Temporary Redirect:

                            <?php
                            header("Location: https://www.example.com/new-page.html");
                            exit();
                            ?>
                            
                            • Explanation: This PHP code temporarily redirects to new-page.html.

                            3. Using JavaScript (Client-Side Redirect)

                            You can use JavaScript for client-side redirects, though it's generally better to use server-side redirects for SEO purposes.

                            a. JavaScript Redirect:

                            <script type="text/javascript">
                            window.location.href = "https://www.example.com/new-page.html";
                            </script>
                            
                            • Explanation: This script redirects the user to new-page.html.

                            4. Using Nginx

                            If your website is hosted on an Nginx server, you can set up redirects in the Nginx configuration file.

                            a. 301 Permanent Redirect:

                            server {
                                listen 80;
                                server_name www.example.com;
                                return 301 https://www.example.com$request_uri;
                            }
                            
                            • Explanation: This code redirects all HTTP traffic to HTTPS with a permanent redirect.

                            b. Redirecting a Single Page:

                            location /old-page.html {
                                return 301 https://www.example.com/new-page.html;
                            }
                            
                            • Explanation: This code permanently redirects old-page.html to new-page.html.

                            5. HTML Meta Refresh (Not Recommended for SEO)

                            You can use a meta refresh tag in the HTML <head> section, but it's not ideal for SEO as it's not a true redirect.

                            <meta http-equiv="refresh" content="0; url=https://www.example.com/new-page.html">
                            
                            • Explanation: This code redirects after 0 seconds to new-page.html.

                            Choosing the Right Redirect

                            • 301 Redirect: Use when you want to permanently move a page or domain. This tells search engines to pass the SEO value from the old URL to the new one.
                            • 302 Redirect: Use when the move is temporary, and you plan to revert to the old URL.

                            Always test your redirects after implementation to ensure they work correctly and that search engines and users are directed to the intended destination.

                            1 Reply Last reply Reply Quote 0
                            • squidgame2024
                              squidgame2024 last edited by

                              Complete redirection process requires using 301 redirection
                              You can redirect your old domain to the new one via Cloudflare or by contacting your hosting manager

                              1 Reply Last reply Reply Quote 0
                              • dotemna
                                dotemna last edited by

                                It depends on which type of redirect you mean and what the purpose is. Here are two common scenarios:

                                For redirecting a single page:
                                You can use a 301 redirect in your .htaccess file (for Apache servers):

                                Redirect 301 /old-page.html https://www.yoursite.com/new-page.html
                                

                                For redirecting an entire domain:
                                To redirect all pages from an old domain to a new one, you can use this code in your .htaccess file:

                                RewriteEngine On
                                RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
                                RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
                                RewriteRule ^(.*)$ https://www.newdomain.com/$1 [L,R=301,NC]
                                

                                Both methods use 301 (permanent) redirects, which is typically best for SEO. Always test your redirects thoroughly to ensure they work as intended across your site.

                                1 Reply Last reply Reply Quote 0
                                • Umairaalam786
                                  Umairaalam786 last edited by

                                  @laurentjb said in How do I carry out a redirect? Is there a code I need to use?:

                                  How do I carry out a redirect? Is there a code I need to use?

                                  To carry out a redirect, you typically need to use specific code or configurations depending on the type of redirect you want to implement and the server or platform you're working with. The most common types of redirects are 301 (permanent) and 302 (temporary).

                                  But I Recommend you Use Plugins
                                  The Best WP Plugin is ( Redirection )

                                  You can use plugins like Redirection or Yoast SEO to manage redirects without needing to write code.

                                  301 Redirect: Use when the original page has permanently moved to a new URL.
                                  302 Redirect: Use when the move is temporary.

                                  1 Reply Last reply Reply Quote 0
                                  • Shahreez
                                    Shahreez @laurentjb last edited by

                                    @laurentjb are you talking about domain redirection ?

                                    1 Reply Last reply Reply Quote 0
                                    • hughcollins
                                      hughcollins @laurentjb last edited by

                                      @laurentjb Yes you can redirect 1 page to another using any redirection plugin.
                                      You can either 301(Moved Permanently) or 302(Moved Temporary) the Url 1 to Url 2

                                      1 Reply Last reply Reply Quote 0
                                      • Hami913
                                        Hami913 last edited by

                                        @laurentjb said in How do I carry out a redirect? Is there a code I need to use?:

                                        How do I carry out a redirect? Is there a code I need to use? Thank you in advance.

                                        To set up a redirect, you typically need to use some code depending on your server environment. For example, if you’re using Apache, you can add a redirect rule to your .htaccess file. Here’s a basic example of a 301 redirect in an .htaccess file:

                                        apache

                                        Redirect 301 /old-page.html http://www.yoursite.com/new-page.html

                                        If you're using Nginx, you would add a redirect rule to your server configuration file like this:

                                        nginx

                                        location /old-page {
                                        return 301 http://www.yoursite.com/new-page;
                                        }

                                        For WordPress or other CMSs, there are plugins available that can help you manage redirects without needing to handle code directly.

                                        I hope this helps! Let me know if you have any more questions. because te same issue a=occure with my site then i resolve it by using this method.

                                        Thank you!

                                        1 Reply Last reply Reply Quote 0
                                        • 1 / 1
                                        • First post
                                          Last post

                                        Browse Questions

                                        Explore more categories

                                        • Moz Tools

                                          Chat with the community about the Moz tools.

                                        • SEO Tactics

                                          Discuss the SEO process with fellow marketers

                                        • Community

                                          Discuss industry events, jobs, and news!

                                        • Digital Marketing

                                          Chat about tactics outside of SEO

                                        • Research & Trends

                                          Dive into research and trends in the search industry.

                                        • Support

                                          Connect on product support and feature requests.

                                        • See all categories

                                        Related Questions

                                        • JamesDavison

                                          Value of using spaces or no spaces on product category page varient keywords

                                          keywords page grader several search terms category page

                                          Hello, all fellow Mozzers,
                                          I have taken over a project and this account, so can't change the username according to MOZ.🙃 We run an eCommerce website, and to me, some of the content is conflicting as some pages have more information content than what I would put in a commerce page, but this is how the boss wants it to work, personally, I would separate the content out.
                                          The page I'm working on:
                                          https://www.longstonetyres.co.uk/tyres/205-70-14.html
                                          and this is an example of the rest of these types of pages, I will be tackling:
                                          https://www.longstonetyres.co.uk/tyres/125-15.html I was tasked to improve SEO ranking, when using the MOZ page grader I had a score of 24 out of 27 83% SEO score and 3-page problems. 7th position in Google for the search term 205/70 R14 As it is a generic product listing page, It was pointless to add to the URL and the Internal links I can't reduce as these are links to products, so I went to reduce the
                                          keyword stuffing and making the page content more natural, this improved the page to 25 out of 27, 87% SEO score and 2-page problems. Improvement to 3rd position in Google, but he wants to chase 1st place to be above his competitors, which is fair enough. It turns out that in the past, they have used this type of page to try and get a high ranking for several search terms, as it is a different variation on a tyre size terms are:
                                          205/70 R14, 205/70R14, 205/70 R 14
                                          205/70 X 14, 205/70X14, 205/70 X14
                                          and so on for all the different ways you can search for this tyre size. He is also convinced Google will see these as different search terms, and while I agree to an extent, this causes Keyword Stuffing on the page, which in turn was harming the rankings. Each product listed on the page already has its own title 205/70 R14, 205/70 HR14 and so on, so my question is. What is the best practice for writing content on these types of pages to gain high rankings for several Keywords, and what value does writing the same keyword with spaces and no spaces have? Any help or advice is welcome, so I have a better understanding of how to approach this for this page and the rest of the site. Cheers Mal

                                          On-Page Optimization | | JamesDavison
                                          0
                                        • Emily.R.Monrovia

                                          When to re-write and redirect a blog url?

                                          urlredirect optimization content marketing seo tactics content development redirect

                                          What are best practices for rewriting (and then redirecting) blog URLs? I refresh old blog posts on our blog every month and many of them have URLs that are too long or could be improved. However, many of them also already get decent organic traffic and I don't want to lose traffic due to a URL redirect. Are there any best practices or "rules" I can follow when deciding whether to re-write and redirect blog URLs?
                                          Thanks!

                                          Content Development | | Emily.R.Monrovia
                                          0
                                        • Billywig

                                          Solve Redirect Chains

                                          redirect help http

                                          I've gotten a few Redirect Issues that involve Redirect Chains, with the https:// version redirecting to the www. version and then redirecting to the right URL. Here is an example:
                                          Schermafbeelding 2021-12-07 om 11.04.32.png I've tried setting a direct redirect between the first and the last URL, but WordPress doesn't seem to allow that (it's overwritten). I've also tried checking the internal links to make sure that none of the links are the first one. They don't seem to be there. Does anyone have any tips on solving these Redirect Chains?

                                          On-Page Optimization | | Billywig
                                          0
                                        • DVLighting

                                          Is using a H1 tag in a logo image bad for SEO?

                                          We have brand logos on certain pages that have H1 tags in them - the H1 text being the brand's name, as this is what we'd want the title of the page to be.  The logos are at the top of the page instead of a written title. But is this the best option for SEO? Do search engines value H1 tags in images as highly as a standard H1 tag?Would it be better for SEO to add an alt tag to the logo and add a separate H1 tag on the page that's also the name of the brand?

                                          On-Page Optimization | | DVLighting
                                          0
                                        • ViviCa1

                                          Using Schema markup for Feefo reviews

                                          I am a little confused about whether or not it is ok to use Schema markup with reviews collected through Feefo. We use Feefo to collect reviews from our customers and these get displayed on our website. We get service ratings as well as product ratings through Feefo. My question is: Is it ok to use Schema markup for these? I would have thought they would fall under 3rd party reviews, but this article from the Feefo website seems to suggest that it would be ok to use markup in the way they recommend. Can anyone confirm how Google handles review markup like this? Thanks in advance!

                                          On-Page Optimization | | ViviCa1
                                          0
                                        • ITsoldSEO

                                          Naked domain redirection info

                                          Hi Guys Been reading one or two posts about 'naked domains' v the 'www' derivative and was wondering... What is your opinion on this, is there a definitive benefit to your business in making the switch in terms of ranking? Apart from the Google released info, do you have any further recommended reading on this subject matter? Thanks in advance Daren

                                          On-Page Optimization | | ITsoldSEO
                                          0
                                        • JesusD

                                          Difference in using dividers in TITLE TAG

                                          Hi everyone, i know that dividers in title or even title tag doesnt have much of an impact on better rankings. I had great rankings for many keywords, not using dividers or using only one divider. However for better reading comprehension and usability, and also aesthetics i started to use the pipe as my main divider and other secondary dividers. I saw many pages drop in rankings vs other less competent and with less content pages. My format was as follows: Product Brand | Product description - Additional info or local info ie.  Fiber Glass MBI | Insulation Batts for Home and Commercial use -  Acoustic and Thermal Insulation I changed the format for a handful of pages, and saw immediate results on rankings and traffic on those pages. Product Brand with Product Description - Additional Info ie. Fiber Glass MBI Insulation Batts for Commercial use - Acoustic and Thermal Insulation. Does it sound like something i should implement page wide. I personally like the aesthetics of the pipe as it gives a cleaner look, but the better rankings on the changed pages with using only one divider makes me think.  Does it sound familiar, or its just a coincidence, Regards,

                                          On-Page Optimization | | JesusD
                                          0
                                        • oneresult

                                          Do we need to use the canonical tag on non-indexed pages?

                                          Hi there I have been working in / learning SEO for just over a year, coming from a non dev background, so there are still plenty of the finer points on-page points I am working on. Slowly building up confidence and knowledge with the great SEOMoz as a reference! We are working on this site http://www.preciseuk.co.uk (we are still tweaking the tags and content by the way- not finished yet!) Because a lot of the information is within accordians, a page is generated for each tab of the accordian expanded, for example: http://www.preciseuk.co.uk/facilities-management.php is the main page but then you also have: http://www.preciseuk.co.uk/facilities-management.php?tab=0 http://www.preciseuk.co.uk/facilities-management.php?tab=1 http://www.preciseuk.co.uk/facilities-management.php?tab=2 http://www.preciseuk.co.uk/facilities-management.php?tab=3 http://www.preciseuk.co.uk/facilities-management.php?tab=4 http://www.preciseuk.co.uk/facilities-management.php?tab=5 All of which are in the same file. According to the crawl test, these pages are not indexed. Because it is all in one file, should we add the canonical tag to it, so that this is replicated in all the tab pages that are generated? eg. Thanks in advance for your help! Liz OneResult
                                          [email protected]

                                          On-Page Optimization | | oneresult
                                          2

                                        Get started with Moz Pro!

                                        Unlock the power of advanced SEO tools and data-driven insights.

                                        Start my free trial
                                        Products
                                        • Moz Pro
                                        • Moz Local
                                        • Moz API
                                        • Moz Data
                                        • STAT
                                        • Product Updates
                                        Moz Solutions
                                        • SMB Solutions
                                        • Agency Solutions
                                        • Enterprise Solutions
                                        • Digital Marketers
                                        Free SEO Tools
                                        • Domain Authority Checker
                                        • Link Explorer
                                        • Keyword Explorer
                                        • Competitive Research
                                        • Brand Authority Checker
                                        • Local Citation Checker
                                        • MozBar Extension
                                        • MozCast
                                        Resources
                                        • Blog
                                        • SEO Learning Center
                                        • Help Hub
                                        • Beginner's Guide to SEO
                                        • How-to Guides
                                        • Moz Academy
                                        • API Docs
                                        About Moz
                                        • About
                                        • Team
                                        • Careers
                                        • Contact
                                        Why Moz
                                        • Case Studies
                                        • Testimonials
                                        Get Involved
                                        • Become an Affiliate
                                        • MozCon
                                        • Webinars
                                        • Practical Marketer Series
                                        • MozPod
                                        Connect with us

                                        Contact the Help team

                                        Join our newsletter
                                        Moz logo
                                        © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                                        • Accessibility
                                        • Terms of Use
                                        • Privacy

                                        Looks like your connection to Moz was lost, please wait while we try to reconnect.