Solved

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

Posted on 2008-10-21
6
597 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.

770 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