Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9019819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:51:56+00:00 2026-06-16T04:51:56+00:00

I am trying to do a canonical redirect from this url www.mysite.com/page.php?id=1&title=aaa To this:

  • 0

I am trying to do a canonical redirect from this url

http://www.mysite.com/page.php?id=1&title=aaa

To this: http://www.mysite.com/1_aaa

I wrote this function:

function canonicalRedirect($url)
{

    if (strtoupper($_SERVER['REQUEST_METHOD']) == 'GET')
    {
        $canonical = $url;
        if (!preg_match('/'.str_replace('/','\/',$canonical).'/', $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))
        {
            header('HTTP/1.0 301 Moved');
            header('Cache-Control: no-cache');
            header("Location: $canonical");
        }
    }
}

And in the page.php I put this code:

canonicalRedirect($url);

Retrieving the $url variable from a MySQL query. However when I try to run it I get this error (I am using Firefox): The page isn’t redirecting properly

I am thinking that the page is self-redirecting but how can I solve this problem? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:51:57+00:00Added an answer on June 16, 2026 at 4:51 am

    finally I managed to solve my problem. I rewrited my function like this:

    function canonicalRedirect($url)
    {
                //Check that there is not query string in the url
        if(preg_match('/\?/', $_SERVER["REQUEST_URI"])) {
            header('HTTP/1.0 301 Moved');
            header('Cache-Control: no-cache');
            header("Location: $url");
        }   
    }
    

    Then in the page.php code I wrote this:

     // code to retrieve the canonical url from MySQL
     // $row is the array with the url data and $canonicalurl is obviously the canonical url
    
    
    if($_GET['title'] != $row['url_title']) {
    
      header("HTTP/1.1 301 Moved");
      header('Status: 301 Moved Permanently', true);
      header("Location: ".$canonicalurl."",TRUE,301);
    }
    else {
    }
    
    canonicalRedirect($canonicalurl);
    

    Bye!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set the canonical URL for my site (macton.com) to add the
I'm trying to get the 64-birmingham out of ... name=title /> <link href=http://www.domain.com/cities/64/deals/147943-local-coupon-book rel=canonical
I'm working on parse generator for PHP . Currently I'm trying to implement canonical
I'm trying to implement canonical URLs and combine it with custom route-classes. The URL-scheme
I want to ask about canonical URL. Lets assume this URL structure: /category_A/page1 /category_B/page1
I am trying to figure out the canonical way to add elements to a
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to figure out how I can do this properly. The print_r looks like
trying to figure out why this is happening - I have an input text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.