Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 23rd, 2008, 03:22 PM
dandcp's Avatar
dandcp dandcp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: CA, USA
Posts: 249 dandcp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 7 h 28 m 37 sec
Reputation Power: 5
mod_rewrite - Create easier to read URL from longer link.

I was sent over here to ask this forum as I hear this is an Apache question. I don't know anything really about messing with Apache and don't want to mess up anything in httpd.conf

I was told mod_rewrite is what I need. I am hosted with westhost and seems that mod_rewrite is already set up.

I have these dynamically created pages for each staff member. like this.
http://www.domain.com/staff/results.php?NameID=1
of course each staff has a different name id #.

They have been asking if there is an easier to read URL to tell their friends. For example:
http://www.domain.com/JohnSmith
that would forward to the correct staff id page for that name. Of course John Smith is first and last name of NameID #1.

I have set up the .htaccess file.
so far just this
RewriteEngine On

I assume I need something like this
RewriteRule ^([^/]+)?$ staff/results.php?name1=$1

But I don't really understand what is happening or what I need to put there exactly.
How does it grab the info from the database and know that John Smith goes to NameID #1?

Thanks in advance for your help.

Reply With Quote
  #2  
Old April 24th, 2008, 01:59 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,124 jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 10 h 58 m 38 sec
Reputation Power: 717
So you want to be able to use the full name instead of the unique ID?

Are the names always going to be unique? Probably not, and that's why you usually use the ID.

Look at the MOD REWRITE sticky for "search on 404" (I believe it's Example 3) to see how to do the rewrite portion correctly since that's basically what you're doing.

You will then need to modify results.php to search the database based on the name that's been passed instead of the ID that's been passed.
__________________
# Jeremy

Explain your problem instead of asking how to do what you decided was the solution.

Reply With Quote
  #3  
Old April 28th, 2008, 04:50 PM
dandcp's Avatar
dandcp dandcp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: CA, USA
Posts: 249 dandcp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 7 h 28 m 37 sec
Reputation Power: 5
Quote:
Originally Posted by jharnois
So you want to be able to use the full name instead of the unique ID?

Are the names always going to be unique? Probably not, and that's why you usually use the ID.

Look at the MOD REWRITE sticky for "search on 404" (I believe it's Example 3) to see how to do the rewrite portion correctly since that's basically what you're doing.

You will then need to modify results.php to search the database based on the name that's been passed instead of the ID that's been passed.


Thanks, I think I actually figured this out! Pretty cool I must say.

I have my .htaccess file in the root folder and is this.
Code:
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ staff/results.php?LastName=$1 [L]

I went with LastName for now as all of my staff (only 41 so far) have different names. I wasn't sure how to separate the REQUEST_FILENAME into the 2 names if someone did www.domain.com/SmithJohn
And yes, I changed the code in results.php page to work properly.

The only thing now is if there is an actual 404 error page needed for a file or folder that doesn't exist how do I get it to forward to the error page instead of going to the results page?

For example, if someone enters www.domain.com/blah Obviously blah is not someones last name. and doesn't exist as a file/folder. That needs to forward to an error page doens't exist page.

Any ideas. Otherwise I am pretty much there!
Thanks again.

Reply With Quote
  #4  
Old April 29th, 2008, 02:32 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,124 jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 10 h 58 m 38 sec
Reputation Power: 717
I would suggest doing that in results.php. The URL is considered user input, so it should be validated like any other user input.

The details would vary based on your implementation, but you could check the database for the last name and use PHP's header() to send the appropriate 404 response and redirect to a 404 webpage.

The other approach is to move your .htaccess file into a folder and change the links to domain.com/folder/lastname. This would allow basic 404 handling for domain.com/foo, but you'd still need to address domain.com/folder/foo in results.php.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > mod_rewrite - Create easier to read URL from longer link.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway