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. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Intermediate & Advanced SEO
    4. Php 301 redirect

    Php 301 redirect

    Intermediate & Advanced SEO
    5 3 683
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ocelot
      ocelot last edited by

      Hi

      I am migrating an old wordpress site to a custom PHP site and the URL profiles will be different, so want to retain all link profiles and more importantly if a user visits the old urls via search then they are seamlessly transferred to the new equivalent page

      For example

      www.domain.com/about-us is going to need to redirect to www.domain.com/aboutus.php

      www.domain.com/furniture is going to need to redirect to www.domain.com/furniture-collections.php

      etc

      What is the best way of achieving this apart from .htaccess as not 100% confident of doing this.  Could it be done via PHP or using meta tags?

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

        There are various ways of doing this and yes the good ol htaccess can be a bit daunting at first.

        Check this page out, should help you.
        http://www.webconfs.com/how-to-redirect-a-webpage.php

        You cannot do a 301 redirect with meta tags - a meta tag "refresh" does not provide a 301 redirect.

        Useful hint: Before commiting to it, try using the same script either in PHP or HTACCESS but with a 302 (temporary redirect) - then test it works and then make it a 301 (permanent redirect) - that way if you get it wrong, Google will not take the permanent instruction.

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

          Hi

          Thanks for the link, it mentions under php

          Header( "HTTP/1.1 301 Moved Permanently" ); 
          Header( "Location: http://www.new-url.com" ); 
          ?>

          So how would I implement multiple page changes in the code above i.e.

          www.domain.com/about-us is going to need to redirect to www.domain.com/aboutus.php
          www.domain.com/furniture is going to need to redirect to www.domain.com/furniture-collections.php

          bjs2010 1 Reply Last reply Reply Quote 0
          • bjs2010
            bjs2010 @ocelot last edited by

            OK - take this page: www.domain.com/about-us

            Presuming that this is a php page, open it up in an editor and insert this code right at the top
            Header( "HTTP/1.1 301 Moved Permanently" );
            Header( "Location: http://www.domain.com/aboutus.php" );
            ?>

            and repeat this same procedure for any other files you need to redirect.

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

              Hi, Not meta tags.  If no other way, You should do it with PHP  header() function.

              <code>header("HTTP/1.1 301 Moved Permanently"); header("Location: /somelocation");</code>
              

              But you need to add some conditions to determine if the page should be redirected. For example to redirect /example.html  to https://www.new-domain.com/example   you need to write something like:

              if (isset($_SERVER['REQUEST_URI']) && parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) == '/example.html')

              {header('HTTP/1.1 301 Moved Permanently');header('Location: https://www.new-domain.com/example');exit();}

              It can be a lot of code, if you need to redirect many pages. In this case, You can try to use PHP 301 Redirect Generator -  https://www.301-redirect.online/php-header-location-generator

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              • 301 redirects
                ThomasHarvey
                ThomasHarvey
                0
                6
                203

              • If you do 302 redirect then change to 301 redirect do you lose all link juice?
                EricaMcGillivray
                EricaMcGillivray
                0
                3
                792

              • 301 Redirect from ASP.NET to PHP...Is it possible?
                AlanMosley
                AlanMosley
                0
                8
                1.6k

              • How to use a 301 Redirect when the first 301 Redirect is not the same as what's indexed?
                PatriotOutfitters81
                PatriotOutfitters81
                0
                3
                66

              • 301 Redirect To Another 301 Redirect
                cbielich
                cbielich
                0
                5
                247

              • 301 redirects
                jwdl
                jwdl
                0
                5
                113

              • How to conduct catch 301 redirects & have the separate 301 redirects for the key pages
                BenRWoodard
                BenRWoodard
                0
                2
                288

              • Multiple 301 redirects considered a redirection chain?
                jmueller
                jmueller
                1
                16
                5.0k

              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