TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-28-2008, 04:43 AM   #1 (permalink)
The Contributor
 
Join Date: Apr 2008
Location: Nevada, USA
Posts: 52
Thanks: 10
h0ly lag is on a distinguished road
Default Good 'ol mod rewrite help needed...

Ok, first off anyone taking time to read this, thanks. Now what I've made is one of those URL shortening scripts. Like TinyURL. Anyhow, I want to be able to rewrite my URLs like they do.

The rewrited URL
Code:
domain.com/random-url
to my actual redirect page

that looks like
Code:
domain.com/redirect.php?url=random-url
It works great other wise. It's just not very clean and short anymore when you have redirect.php?url=bla-bla.
__________________
Send a message via AIM to h0ly lag Send a message via MSN to h0ly lag
h0ly lag is offline  
Reply With Quote
Old 10-28-2008, 09:53 AM   #2 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

This should work, admittedly Apache stuff isn't my strong point.
Code:
RewriteEngine on
RewriteBase /
RewriteRule ^random-url redirect.php?url=random-url
Hope that's what you wanted.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 10-28-2008 at 12:15 PM.
sketchMedia is offline  
Reply With Quote
Old 10-28-2008, 11:55 AM   #3 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

It'll probably make more sense to use a regular expression to match short urls and throw them into the redirect page.

Code:
# Turn on URL rewriting
RewriteEngine On

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite to redirect.php
RewriteRule ^[a-z0-9_-]{4,7}$ redirect.php?url=$0 [NC,L]
Of course, the pattern might need changing to suit your own application as the one above might be a little too loose (or tight!) in what's allowed or not (alpha-numeric, underscore or dash between 4 and 7 in length (inclusive)).
Salathe is offline  
Reply With Quote
The Following 2 Users Say Thank You to Salathe For This Useful Post:
h0ly lag (11-01-2008), sketchMedia (10-28-2008)
Old 11-01-2008, 05:52 AM   #4 (permalink)
The Contributor
 
Join Date: Apr 2008
Location: Nevada, USA
Posts: 52
Thanks: 10
h0ly lag is on a distinguished road
Default

Thank you very much Salathe. Your help was invaluable.
__________________
Send a message via AIM to h0ly lag Send a message via MSN to h0ly lag
h0ly lag is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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


All times are GMT. The time now is 08:30 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design