Solved

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

Posted on 2008-10-21
6
593 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
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.

 

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

912 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

19 Experts available now in Live!

Get 1:1 Help Now