?
Solved

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

Posted on 2008-10-21
6
Medium Priority
?
610 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 1600 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
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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…
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 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…
Suggested Courses

800 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