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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:47:57+00:00 2026-05-23T02:47:57+00:00

I’m having a play around with using mod_rewrite to provide a better looking URL

  • 0

I’m having a play around with using mod_rewrite to provide a better looking URL to the user, and to search engines – as is fairly common practice on many dynamic websites.

So for instance, I began with:

http://www.mydomain.com/profile/view.php?id=136

Assuming user number 136 is called, for the sake of argument Bob T. Smith the 3rd (apologies Bob, if you exist).

As far as I understand it, I must have a variant of Bob’s name in my ‘nasty’ URL, because you can only rewrite what exists – so i’d need to change my code so that this URL finds the profile we’re looking for:

http://www.mydomain.com/profile/view.php?id=bob-t-smith-the-3rd

can now become

http://www.mydomain.com/profile/bob-t-smith-the-3rd

I’m using a custom function to convert underscores & spaces to dashes, strip any non alpha-numeric characters and then lower case everything to make the URL look really nice.

And so within my page, rather than looking up on the very unique primary key that is ‘136’, I now have to look up on the users name – but the sanitized version, so i’m using something like this – because MySQL can’t do regular expressions:

SELECT LOWER(REPLACE(REPLACE(REPLACE('Bob T. Smith the 3rd'," ","-"),"_","-"),".",""));

The name would obviously be replaced by whatever came in on the URL, cleaned up.

The problem i’m expecting is that without wanting to chain together MySQL REPLACE() functions to handle every conceivable illegal character (which would be confusing, hard to maintain, and probably inefficient), and without the ability to do regular expressions on the query side, how can I ensure the user profile is found and gets returned every single time?

If Bob signed up as ‘Bob T. Smith! (The 3rd)‘ – I would still clean that up in PHP to bob-t-smith-the-3rd because of the preg_replace that strips the exclamation point and the parentheses, but my query – unless I added more REPLACE() functions, wouldn’t find that user.

Should I just ensure that users can only sign up using A-Z, 0-9, dash and underscore?

Should I in some way continue to pass the unique numerical ID but just omit it from the rewrite rule somehow?

Am I missing the point entirely? Is there an accepted way of doing this that I just haven’t thought of?

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-05-23T02:47:58+00:00Added an answer on May 23, 2026 at 2:47 am

    Correct me if I am missing something but why don’t you just strip the username from the dashes you added in your rewrite rule when the php script is called?

    $undashed_username = explode("-",$dashed_username);
    $username = implode(" ",$undashed_username);
    

    which you can then search for on your database.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.