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. Link Building
    4. Urls rewriting "how to" with .htaccess

    Urls rewriting "how to" with .htaccess

    Link Building
    22 3 4.6k
    • 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.
    • mozllo
      mozllo @dephelis last edited by

      Hi, i was thinking of the whole picture of baptiste solution, you say :

      "Baptiste: On the new linux hosting set up an .htaccess file in the root of the site directory that redirects all id=xxxx requests to a redirect.php file on your server. The redirect.php file will need to interrogate a database with a table of the mappings and automatically redirect to the correct page via php scripting."

      it means that wiithout any credentials, any database access, if you have urls from the site you need to move to,  you can redirect any urls site to another one !?

      Hum..i think i miss something ..

      baptisteplace 1 Reply Last reply Reply Quote 0
      • baptisteplace
        baptisteplace @mozllo last edited by

        You should get all the url of the old site with Xenu's Link Sleuth, then create a PHP array of oldUrl => newUrl and put it in your redirect script.

        So you have in the htaccess :

        RewriteCond %{REQUEST_URI}  ^/home/newscontent.asp
        RewriteCond %{QUERY_STRING} id=([0-9]+)
        RewriteRule ^(.*)$ redirect.php?id=%1 [L]

        In the redirect.php file, you have :

        $redirect = array("/home/newscontent.asp?id=1133" => "/name-of-the-article"); // 800 times (for all url)

        if(isset($redirect[$_SERVER['REQUEST_URI']])) {
            header("Status: 301 Moved Permanently", false, 301);
            header("Location: http://www.mydomain.com/".$redirect[$_SERVER['REQUEST_URI']]);
            exit();
        }

        // Send a 404 if you don't have a redirect

        1 Reply Last reply Reply Quote 0
        • 1
        • 2
        • 2 / 2
        • First post
          Last post
        • How do I set "no follow"
          Kuhliff
          Kuhliff
          0
          3
          32

        • Impact of "noopener" Links
          mostcg
          mostcg
          0
          3
          5.1k

        • Links to "boring" pages
          grobro
          grobro
          0
          7
          100

        • What would you consider a "bad link"?
          MarieHaynes
          MarieHaynes
          0
          5
          125

        • Difference between rel="nofollow" and rel="no follow"
          DDL
          DDL
          0
          5
          1.5k

        • Keyword + "intitle:resources"
          BenFox
          BenFox
          0
          2
          481

        • "high authority" links
          KeriMorgret
          KeriMorgret
          0
          5
          1.4k

        • What constitutes a "paid link"?
          stevecounsell
          stevecounsell
          0
          4
          1.1k

        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