Solved

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

Posted on 2008-10-21
6
588 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
  • 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now