Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-10-2006, 12:25 PM   #1 (permalink)
DewKnight
Recruit
 
DewKnight's Avatar
 
Join Date: Feb 2006
Posts: 22
DewKnight is on a distinguished road
mod_rewrite question

Alright, I have a question about mod_rewrite. I am pretty sure that this is what I need to use to go about what I would like to do.

Here is what I am doing. I have a website I am redoing ( www.coloradomountaincabins.com ). All of the cabins and such are going to be stored in a database now. Instead of each cabin having a page, I want to have one page (cabin.php) and use a variable to select the cabin they want to view, and then select that information from the database. I have it working so much as I can go to cabin.php?id=5 and it will display cabin 5. What I want to try now, is instead of having the url's like that, have the links all be say domain.com/cabin/05 and that will display cabin.php?id=5

From what I know, mod_rewrite will do this for me.. I have been looking around at various tutorials.. and have sort of an idea of how I would do this.. but I am confused by seeing that query strings are passed seperately.. how would I go about doing this......? Thank you in advance

Note: I am not going to link to the current page that I have these test pages on, because I know they have pretty wide open things in them that can be exploited right now. I am checking the id that I am using to submit to choose the cabin for length. If it is longer than 2 characters I am having the script die. Is there a better way that I can do this? I figure that would probably keep anything that somebody tries to inject way, because I figure it would be longer than 2 characters
DewKnight is offline   Reply With Quote
Old 03-10-2006, 12:46 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
if your server runs apache and supports mod rewrite, then all you need to do is make a file named .htaccess and place it in your web root directory.
Code:
RewriteEngine on
RewriteRule ^cabin/[0-9]+)$ cabin.php?id=$1 [L]
sometimes mod rewrite doesn't like it when you name a directory the same as your script ( i don't know why ) so you may have to rename cabin.php to cabin_rw.php ( or something other than cabin.php )

if you are going to send '05' instead of just '5' , then you may have to modify the var passed in with php as well.
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
anyone know a lot? question concerns php also. Rotkiv HTML, XML, Javascript, AJAX 7 01-12-2006 12:09 PM
Compiler Question cheawick Standard C, C++ 3 04-30-2004 03:06 AM
Question about getting Arrays metazai PHP 16 04-24-2004 06:27 PM
another question Ilya020 HTML, XML, Javascript, AJAX 5 08-20-2003 11:54 AM
DB Design Question Part II sde Program Design and Methods 3 05-10-2003 12:24 PM


All times are GMT -8. The time now is 04:28 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting