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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:20:22+00:00 2026-06-13T05:20:22+00:00

I have URL’s like so mysite.com/view.php?id=123 I have changed the URL’s to look like

  • 0

I have URL’s like so

mysite.com/view.php?id=123

I have changed the URL’s to look like this with .htaccess

mysite.com/123/page-title.html

Now, since the “page-title” part wasn’t part of the original URL, and is information from a mysql table that corresponds to the id “123”, how can I 301 redirect the old URL’s to the new URL’s ?

Surely there must be some PHP involved, but I don’t know how to write that in .htaccess…

  • 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-13T05:20:23+00:00Added an answer on June 13, 2026 at 5:20 am

    Now, since the “page-title” part wasn’t part of the original URL, and is information from a mysql table that corresponds to the id “123”, how can I 301 redirect the old URL’s to the new URL’s ?

    The only rewrite rules you need is to make the nicer looking URL route to view.php, which it sounds like you’ve already got. Probably looks something like this:

    RewriteCond %{REQUEST_FILENANE} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([0-9]+)/([^/]+)\.html /view.php?id=$1 [L]
    

    When that request gets to view.php you can check the $_SERVER['REQUEST_URI'] variable, and it will look like '/123/page-title.html'. When you see that, you know just to serve the content and be done with it.

    However, when the view.php looks at $_SERVER['REQUEST_URI'] and it looks like '/view.php?id=123', then you know someone has requested the page http://mysite.com/view.php?id=123 and not the nicer looking URL. When this happens, the view.php needs to look up the page-title from the database using $_GET['id']‘s sanitized value, then create a redirect (all this needs to happen before anything gets printed to the browser):

    Something like:

        header('HTTP/1.1 301 Moved Permanently');
        header('Location: /' . $id . '/' . urlencode($page-title) . '.html');
        exit();
    

    That’ll redirect the browser to the page http://mysite.com/view.php?id=123. You don’t need anything else in htaccess.

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

Sidebar

Related Questions

Currently i have url parameters like this http://www.website.com/index.php?user&page=edit And in index.php i have set
Say currently I have url like : http://mydomain.com/showpost.php?p=123 Now I want to make it
I have URL like this http://example.com/index.php?id=10 . How can i check whether this URL
I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/ Now i want to
My permalink structure is set so I have url.com/page I made a basic PHP
I have URL: http://www.mysite.com/ here is: $date = new DateTime(2011-11-28); this show me: 2011-11-28
I have url that looks like this... http://www.example.com/accounts/?token=111978178853984|683b8096732be7fd725d3332-557626087|m9lSbmoYhZ6Yut4OC3smY1fRf1E. from the token 111978178853984|683b8096732be7fd725d3332- 557625434 |m9lSbmoYhZ6Yut4OC3smY1fRf1E
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
If I have url like this: www.example.com/product/yellow-bed is it possible to retrieve product name
So I have url like this: example.com?category=Home&category=Test I know that in the views I

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.