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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:17:34+00:00 2026-05-17T22:17:34+00:00

I have a PHP based site with dynamic pages , such as /page.php?ID=1. The

  • 0

I have a PHP based site with dynamic pages , such as /page.php?ID=1.
The ID in the URL represents a unique key in a MySQL database of an entry which have a “Name” field as well.
I understand that in order to convert all my URLs from /page.php?ID=1 to /page/New-York (where the Name field of row ID=1 is New York) I need to use .htaccess file.

What will be the best way to do that? How can I use the following:

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^ID=1$
RewriteRule ^/page.php$ http://www.example.com/page/New-York [L,R=301]

but in a way that it will retrieve the Name (in this case New York) from the MySQL database, for all entries?


Edit:

Repox’s answer is very good for the next step, that is how to fetch an entry from the DB once I set up the static URL.

However, I have another problem which I need to begin with: Since my site is couple of years old, Google has already indexed all my pages, so /page.php?ID=2 and /page.php?ID=3 are already in Google’s database. So I need to create a 301 Redirection (in the .htaccess) for EACH existing page to the new page, i.e:

redirect 301 /page.php?ID=1 /page/new-york
redirect 301 /page.php?ID=2 /page/berlin
and so on...

Is there any better (and maybe more efficient) way to do it, than to just write 2500 line of entries and their target? The problem I see is that I can not query my DB from the .htaccess file so there is not really a way to create a short rule.

Thanks,

Joel

  • 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-17T22:17:34+00:00Added an answer on May 17, 2026 at 10:17 pm

    You will have to let PHP interpret the pages for you.

    The simple way is to add field more to your table, called Webname, and for the page named ‘New York’ the websafe name would be ‘New-York’.

    page.php would then have query the table for the Webname instead of the pageId.

    Your .htaccess should then look more something like:

    RewriteEngine On 
    RewriteRule ^page/?$ page.php?pageName=$1 [NC,L]
    

    Your websafe pagename would then be available in page.php in $_GET[“pageName”].

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

Sidebar

Related Questions

I'd like to have a page in php that normally displays information based on
I have a PHP site based on a simple MVC principle. I currently have
I am creating a very large PHP MVC-based site that will have a large
I'm working with a closed community site (PHP-based) of about 100 users, and one
I need to implement a SSO between a SharePoint site and a custom PHP-based
On a PHP-based web site, I want to send users a download package after
I have a PHP based website that uses coupon codes. I can restrict search
I have been writting a keyword search script based on this tutorial: http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/ Like
I have PHP configured so that magic quotes are on and register globals are
We have PHP 5.2.6 deployed to c:\php and in that folder there is the

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.