Solved

Rewrite URL form index.php?ID=2 -> products.php, etc.

Posted on 2008-10-21
6
604 Views
Last Modified: 2013-12-13
I am running Apache, PHP and MySQL on windows IIS.

I have an index.php page with a switch statement:
switch($_REQUEST["ID"]){
   case 1:
        exceute code for home page
        break;
   case 2:
        exceute code for products
        break;
   case 3:
        exceute code for contact us
        break;
}

I want all my code to reside on my index.php page but want users to access my page using other page names (i.e. products.php and contactus.php)

Home Page: index.php?ID=1 -> index.php
Products: index.php?ID=2 -> products.php
Contact Us: index.php?ID=3 -> contactus.php
Contact Use: index.php?ID=3 - > contactus.php

I am new to .htaccess

Please go slow
0
Comment
Question by:khourykris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
Hube02 earned 400 total points
ID: 22775226
You would need to place a series of rewrite rules in your .htaccess file for the site, one for each page, then in the code/html/whatever, you would need to point them to the correct page.

RewriteEngine on

// send index.php to index.php with ID=1
RewriteRule index.php index.php?ID=1

// send products.php to index.php with ID=2
RewriteRule products.php index.php?ID=2

etc...
0
 
LVL 18

Expert Comment

by:Hube02
ID: 22775238
This is for Apache, which you indicate you are running as the server. I notice you also have IIS listed. Is the server Apache or IIS? or is it just Apache on a windows box?
0
 

Author Comment

by:khourykris
ID: 22776582
I am running Apache on my local system(windows). IIS is disabled.

I tried adding the above script to an .htaccess file in the root directory of my project and I get the following error when I try to visit any of the pages.

*****************************************************************
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
*****************************************************************

Any Ideas?
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

Author Comment

by:khourykris
ID: 22777013
I realized I didn't have "rewrite_module" turned on. Now it's working.
0
 

Author Comment

by:khourykris
ID: 22777057
I'm not sure if I need to ask a whole new question for this but:

Can I integrate the .htaccess with mysql somehow. In other words have the above htacces page generated by in mysql and php?

I increased the points. :)
0
 
LVL 3

Expert Comment

by:sistemu
ID: 22778251
Maybe if you create a php script to rewrite the .htaccess file from time to time (using a Cron).
But you must have the rights to change the file in the first place.
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question