I'm over the moon for you.
Home
Go Back   Chief Delphi > Technical > IT / Communications > Website Design/Showcase
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Spotlight this post!  
Unread 25-03-2009, 06:21
artdutra04's Avatar
artdutra04 artdutra04 is offline
VEX Robotics Engineer
AKA: Arthur Dutra IV; NERD #18
FRC #0148 (Robowranglers)
Team Role: Engineer
 
Join Date: Mar 2005
Rookie Year: 2002
Location: Greenville, TX
Posts: 3,079
artdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond repute
Re: PHP and URL's

You need a .htaccess file in the base directory of where you want to start changing URLs. It can be even higher than this (such as out of the htdocs folder, hence out of web directory), but your URLs need to reflect this.

Using the Apache guide, the first thing you need to do is use the first line to turn the mod_rewrite engine on.

Then, you put one RewriteRule per line in the .htaccess file. Each line must start with RewriteRule, then a space, then a ^ (which signifies start of the URL you want users to see), then the URL (anything in brackets is a variable), then a $, then a space, then the actual file URL, with $1, $2, $3, etc being the respective variables from the first part. Example:

RewriteRule ^photogallery/([0-9]+)/([a-zA-Z0-9-]+)/([0-9])$ gallery.php?year=$1&gallery_id=$2&page_offset=$3

If gallery.php was located at example.com/gallery.php, then this RewriteRule would allow this URL

example.com/photogallery/2009/this-is-a-test/3
or
example.com/photogallery/2008/i-CAN-has-camelCASE-and-numb3r5/2

Edit: mod_rewrite is "cosmetic only", in that it does not permanently change the actual URL to the file. The real file can still be accessed by gallery.php?year=... url, even with mod_rewrite. The only thing mod_write does is provide a cosmetic placeholder URL to hide the real internal structure, parameters, and even the programming language used from users.

The first variable ([0-9]+) gets stuck where $1 placeholder is. The [0-9] part indicates this can accept any character from 0-9, and the + part indicates that it can have multiple digits. So 3, 34, 345, 3456, 34567 would all work here. Any character not allowed by this will throw an Error 404 on the URL.

The second variable, ([a-zA-Z0-9-]+) will accept all alphanumeric characters, with the addition of the dash - and gets put in the $2 placeholder. Any character not allowed by this will throw an Error 404 on the URL.

The third part ([0-9]) indicates this is only a single 0-9 digit, and nothing else.

Of course the rewrite_rules do not have to be this complex, but this was just an example. If you are looking to make URLs multiple artificial directories deep (such as foo/foo2/foo3), then make sure the HTML code you generate compensates. And last but not least, always put your most complicated and most restrictive cases first in the .htaccess file and work your way to simpler. This is because as soon as Apache finds a RewriteRule that works, it will use that and ignore the rest of the file.

If you get stumped, there are thousands of websites out there with much more detailed information about the intricacies of mod_rewrite that are only a Google search away.
__________________
Art Dutra IV
Robotics Engineer, VEX Robotics, Inc., a subsidiary of Innovation First International (IFI)
Robowranglers Team 148 | GUS Robotics Team 228 (Alumni) | Rho Beta Epsilon (Alumni) | @arthurdutra

世上无难事,只怕有心人.

Last edited by artdutra04 : 25-03-2009 at 06:25.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL MrToast Website Design/Showcase 4 18-03-2005 22:29
PHP and Wiki Error Venkatesh Website Design/Showcase 2 24-07-2004 15:51
PHP, MySQL, and Dropdown lists Raven_Writer Website Design/Showcase 22 01-07-2004 08:05
php and gzip compression Trashed20 Website Design/Showcase 2 12-06-2003 22:11


All times are GMT -5. The time now is 12:06.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi