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. Technical SEO Issues
    4. Query String Redirection

    Query String Redirection

    Technical SEO Issues
    3 2 1.4k
    • 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.
    • JoeQuery
      JoeQuery last edited by

      In PHP, I'm wanting to store a session variable based upon a link that's clicked. I'm wanting to avoid query strings on pages that have content. My current workaround is to have a link with query strings to a php file that does nothing but snags the variables via $_GET, stores them into $_SESSION, and then redirects.

      For example, consider this script, that I have set up to force to a mobile version. Accessed via something like a href="forcemobile.php?url=(the current filename)"

      session_start();

      //Location of vertstudios file on your localhost. Include trailing slash $loc = "http://localhost/web/vertstudios/"; //If GET variable not defined, this page is being accessed directly. //In that case, force to 404 page. Same case for if mobile session variable //not defined. if(!(isset($_GET["url"]) && isset($_SESSION["mobile"]))){ header("Location: http://www.vertstudios.com/404.php"); exit(); }

      //Snag the URL $url = $_GET["url"]; //Set the mobile session to true, and redirect to specified URL $_SESSION["mobile"] = true;header("Location: " . $loc . $url); ?>

      Will this circumvent the issue caused by using query strings?

      1 Reply Last reply Reply Quote 0
      • Getz.pro
        Getz.pro last edited by

        The idea of setting a session variable to direct page content is a great one. I use this to show the difference between two CSS files when I am designing sites. This is also great for query strings that come in from SEM. Rand talked about this before where you capture the string parameters and then redirect to a clean URL so users have a pretty URL to link to.

        Now looking at your code. I do not know why a PHP scripter wants to force a 404? If you are testing a URL string, then find someplace logical to send them : )

        href="forcemobile.php?url=(the current filename)

        I would have a Go Mobile link on the page more something like this at the footer.

        View our mobile version

        Then do your SESSION. If not, ALL your links are going to be ugly and you are only cleaning up the URL. You can test for SESSION and mobile versions of browsers to redirect.

        I hope that helps

        JoeQuery 1 Reply Last reply Reply Quote 0
        • JoeQuery
          JoeQuery @Getz.pro last edited by

          So you're saying that in the webpage file itself, at the top

          if (isset($_GET["mobile"]){
          $_SESSION["mobile"] = $_GET["mobile"];
          $url = //Get the current URL, use RegEx to strip query strings
          header("Location: " . $url);
          }
          ?>

          If that's the case, and if in fact that's SEO friendly, I definitely like that idea!

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          • Query string category pagination
            MickEdwards
            MickEdwards
            0
            3
            260

          • Query Strings causing Duplicate Content
            Alick300
            Alick300
            0
            3
            1.3k

          • Redirect a 301 Redirect
            RedCaffeine
            RedCaffeine
            0
            5
            98

          • How to Remove Old Comment Page Query String URLs
            jonmifsud
            jonmifsud
            0
            2
            151

          • Should I block robots from URLs containing query strings?
            ShearingsGroup
            ShearingsGroup
            0
            4
            681

          • Redirect or not to redirect
            AlanMosley
            AlanMosley
            0
            7
            458

          • Rel canonical with index follow on query string URLs
            panini
            panini
            0
            4
            1.4k

          • How to handle sitemap with pages using query strings?
            oneticsoft
            oneticsoft
            0
            2
            1.4k

          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