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 8256983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:03:18+00:00 2026-06-08T02:03:18+00:00

Just got a question about codeigniters routing when you only want the first segment

  • 0

Just got a question about codeigniters routing when you only want the first segment to be valid. Cant seem to find a good answer when googling.

So I have a basic route for my general pages:

$route['(:any)'] = 'common/pages/view/$1';

Pages is the class and view is the method along with the name of the page as a variable (pretty much like the example on the ci manual).

This works fine when I go to:

www.mysite.com/mypage/

However when I then go to:

www.mysite.com/mypage/randomstring/

This also loads mypage which is essentially a duplicate.

Is their a way to tell the any route to only apply to the first segment and if more exist do a 404?

If worse comes to worse I will just add a check in the method to see if the 2nd segment exists, if so show_404 but just curious as to if it can be done purely in the routes.

Thanks for reading and I hope that makes sense.

  • 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-08T02:03:20+00:00Added an answer on June 8, 2026 at 2:03 am

    You could just use Regex instead?

    $route['([^/]+)'] = 'common/pages/view/$1';
    

    This would prevent the URL after your domain from containing / and if it does, it will call the default 404 page.

    I haven’t tested this but it “should” work 😉

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

Sidebar

Related Questions

I've got a question about something that's just been irritating me. A colleague and
I just had a question about aligning two expand-collapse boxes and got an answer
Just finished reading Jon Skeet's article about events and delegates and got a question.
I've got a question concerning the csv-module in python. I just can't seem to
I have just got an answer to my question about combining the result of
I just wrote a question about caching and it got me thinking. Is using
I just had a question about browsing for files on my IPad. I got
Basic question here, just got curious about coding a simple formula out, and wanted
My other question here just got answered about why pip svn+ was always re-downloading
I was just reading another question about jQuery's synchronous ajax call, and I got

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.