Query String Redirection
-
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?
-
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!
-
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.
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
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
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.
Related Questions
-
Site Redesign: 302 Query
Hi there, We'll be redesigning our website www.example.com and as such want to 302 users from www.example.com and all other pages to a new URL www.example.com/landingpage while we go through the redesign. The new landing page will have copy and a sign up form on it and once the redesign is completed, we plan on removing the 302 and sending all traffic back to the original url www.example.com. I'd just like to check that a 302 is the most relevant option here? Obviously, once redesign is completed we'll 301 any old URLs to their new locations once completed.
Technical SEO | | Hemblem0 -
Redirect to get better ranking
I have three pages of my website ranking for a keyword: landing page and two blogposts. They all rank on top of page 2 (positions 11-13).If I redirect these articles to the landing page, will it help to bring it up in rankings?
Technical SEO | | imoney0 -
301 Redirect with index.asp
I am very new to all of this so forgive the newbie questions I will get better. Ok so after starting a campaign I see that I have many issues including where some pages are being deemed as duplicate content. 1. The report says the http://lucid8.com has duplicate content on 2 other pages 2. When I look at them it shows that http://lucid8.com/index.asp and http://www.lucid8.com are duplicates. 3. Really these are the exactly the same page because the default page that is opened for www.lucid8.com http://www.lucid8.com etc always opens the index.asp page. 4. Now I read that I should do permanent redirects and how to do this via IIS and I tried to do a redirect from index.asp to www.lucid8.com but that does not work because www.lucid8.com is pointing to index.asp and so we end up in a circle. So the question is how do I get rid of these duplicate page references without causing problems. Thanks
Technical SEO | | TroyW0 -
301 redirects reverting to 302 redirects
We recently built a new website with a new site structure. To prevent there being a load of 404's I redirected the old pages to the new relevant pages with 301 redirects. A few days later the SEOmoz crawl report alerted me to a load of 302 redirects. When I looked into this for some reason all of the 301 redirects I set up are reverting to 302 redirects. I did a test by 301 redirecting a made up URL to an existing page and the same thing happens - it 302 redirects. I can't find any settings in WordPress to possibly explain why this is happening. Has anyone got any ideas why this could be?
Technical SEO | | Tone_Agency0 -
301 redirects and OSE
We run a blog/video real estate site (yochicago.com) as one of the venues for sponsored content for our clients looking for off-page SEO and inbound links. I'm working with a client who we've linked to a handful of times in the last few weeks, but I'm not seeing any external links from our site on PRO/OSE. Come to find that our writer has been linking to http://clientsite.com, instead of http://www.clientsite.com, which is the canonical site. I wouldn't have thought that this would make a difference, and about an hour of web research seems to confirm that it shouldn't make a difference, save for losing a little bit of SEO credit. What am I missing? Any input would be appreciated.
Technical SEO | | mikescotty0 -
Canonical tag, CNAME and 301 redirect
I have a website with a couple of domains pointing to one IP address. Let's say I have two domains www.example.com and www.example.ca I also see during my SEO analysis that the example.com and the www.example.com (same for the example.ca and the www.example.ca) are triggering server responses. How do I deal with this issue for best SEO. Canonical links? CNAME, or 301 redirects? thanks
Technical SEO | | casper4340 -
Considering redirecting or canonicalization - Best Practice
Hi, I'm having a techinical problem and I would like advise on the effects this is having on my SEO efforts. My old site www.oldsiteexample.com (live for about 8 years) Directs to my new site www.example.com which is fine BUT When I type me new website into the tool bar both sides are found & do not direct to one domain; www.example.com & example.com (both the same site) What is the best practice here? Direct my new non www to my new www site considering my old website directs to the www. Advise & the SEO affects this is having my website would be greatly appreciated, thank you.
Technical SEO | | Socialdude0 -
Are asp redirects permanent?
I need to redirect a windows-hosted domain with permanent (301) redirects so as to preserve most of the link juice. I would be using asp page-level redirects, as there are only about 50 relevant pages. Are these as effective as linux-based 301 redirects in conserving link juice?
Technical SEO | | waynekolenchuk0