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

  • SEARCH
  • Home
  • 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 7631449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:21:25+00:00 2026-05-31T06:21:25+00:00

I am trying to set a custom route for friendly url when loading a

  • 0

I am trying to set a custom route for friendly url when loading a tag, by that I mean that I want to convert this: http://test.com/en/results?search_query=data&search=tag to this http://test.com/en/tag/data

Tried to do so by setting this in my routes.php:

$route['^(en|es|ro)/tag/(:any)'] = "fetch/results?search_query=$1&search=tag";

But no success, am I doing it wrong?

My routes.php:

$route['default_controller'] = "home";

// URI like '/en/about' -> use controller 'about'
$route['^(en|es|ro)/video/(.+)$']  = "video/id/$2";
$route['^(en|es|ro)/results$']     = "fetch/results$2";
$route['(en|es|ro)/tag/(:any)']   = "fetch/results?search_query=$2&search=tag";
$route['^(en|es|ro)/(.+)$']        = "$2";

// '/en', '/de', '/fr' and '/nl' URIs -> use default controller
$route['^(en|es|ro)$'] = $route['default_controller'];

$route['404_override']  = '';
  • 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-05-31T06:21:27+00:00Added an answer on May 31, 2026 at 6:21 am

    I’m fairly sure the ^ is not necessary. Try without it:

    $route['(en|es|ro)/tag/(:any)'] = "fetch/results?search_query=$1&search=tag";
    

    In that context, ^ will be treated as a literal string. If you wanted top use a regex, I believe you’d have to wrap the regex itself in parentheses, like so:

    $route['(^(en|es|ro))/tag/(:any)'] = "fetch/results?search_query=$1&search=tag";
    

    I’m not 100% certain on that, but if I’m correct both should work. However, routes always assume the first part of the pattern is what the string should start with, so the ^ shouldn’t be necessary anyways.

    One more thing: You aren’t using the second match, but the first. I believe you want to replace $1 with $2 in your route.

    $route['(en|es|ro)/tag/(:any)'] = "fetch/results?search_query=$2&search=tag";
    //       ^^^1^^^^      ^^^2^^                                 ^^
    

    EDIT: Upon further investigation and testing, it seems that Codeigniter cannot properly handle routes that use a query string like ?key=value. If you use a slash before the ? question mark, you can at least get it to route to the right controller and method:

    $route['(en|es|ro)/tag/(:any)'] = "fetch/results/?search_query=$2&search=tag";
    

    A url like this:

    http://example.com/es/tag/Codeigniter's Router

    …will be routed to the results method with this string as an argument, but $_GET will be empty:

    ?search_query=Codeigniter%27s%20Router&search=tag

    So, you could pick apart the argument with parse_str():

    function results($request)
    {
        $request = ltrim($request, '?');
        parse_str($request, $get);
        // echo $get['search_query']
    }
    

    You could always use .htaccess of course, but I understand the desire to keep all the routing logic in one place. Sorry if this isn’t the answer you hoped for, but I’m afraid that without writing a custom router it’s not possible to do this the obvious way in Codeigniter. My suggestion would probably be to find another way to handle your routing and the way you’re accessing data from the URL.

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

Sidebar

Related Questions

I'm trying to create a custom object that behaves properly in set operations. I've
I'm trying to set custom 'name' attribute in django form. I've been trying this
I'm trying to create links such as /redirector/http://www.google.co.uk so that it runs a custom
I'm trying to set up a custom mute button for the embed tag. <embed
I'm trying to set up a custom backend that queries another database, for which
I am trying to set a custom class to an Iterator through the setInfoClass
I am trying to set an image as the background of a custom UIButton.
I am trying to read a custom (non-standard) CSS property, set in a stylesheet
I created a custom RouteHandler for images that I want protected. My RouteHandler simply
I am trying to set custom step (interval) to my Line Chart's horizontal axis.

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.