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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:19:59+00:00 2026-05-20T08:19:59+00:00

I’m aware that there are a hundred articles, tutorials and manuals on Mod Rewrite

  • 0

I’m aware that there are a hundred articles, tutorials and manuals on Mod Rewrite but i tend to learn better by examples, so all i’m asking is for a quick pretty url conversion and i’ll be on my way (so i can dissect exactly what its doing, so i can apply it to others)

I have this URL: http://www.example.com/single.php?id=1

Now it would be great if it could follow the same convention as Stack Overflow where the id=1 is the actual title of the page.

I have the title in a PHP variable if thats any help?

I would be grateful if someone could turn the above into: http://www.example.com/single/here-is-my-cool-title (where the last bit is dynamic, depending on a PHP variable)

Is that possible?

  • 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-20T08:20:00+00:00Added an answer on May 20, 2026 at 8:20 am

    SO actually has the post ID and the title in the url, but they’ll only use the post ID. The title isn’t very suitable, as there may be duplicate posts (same title, different id), title changes, etc. For the url of this question:

    /questions/5142095/pretty-urls-for-web-application
    

    To resolve to this:

    /single.php?id=5142095
    

    The rewrite rule will be:

    RewriteRule ^questions/([0-9]*)/(.*)$ /single.php?id=$1
    

    What this looks for is the start of the uri (after the domain) ^, the word questions, any length of numbers `[0

    This looks for:

    • ^ the start of the URI
    • the word questions
    • a slash /
    • a variable length of numbers [0-9]* (such as 1, 123, 1234 etc)
    • a slash /
    • any length of any character .* (ie the question title)
    • $ the end of the URI

    When the character match (such as [0-9]* or .*) is in brackets, mod_rewrite puts the match result into a numbered dollar variable. In the rule above, [0-9]* matches any number (and any length of numbers) and puts it into $1. The second match .* matches any length of any character, and puts the match into $2.

    Your application will receive the URI on the right side of the rule, with the dollar variables replaced with the matches.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.