TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   XHTML, HTML, CSS (http://www.talkphp.com/xhtml-html-css/)
-   -   Good 'ol mod rewrite help needed... (http://www.talkphp.com/xhtml-html-css/3542-good-ol-mod-rewrite-help-needed.html)

h0ly lag 10-28-2008 04:43 AM

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.

sketchMedia 10-28-2008 09:53 AM

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.

Salathe 10-28-2008 11:55 AM

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)).

h0ly lag 11-01-2008 05:52 AM

Thank you very much Salathe. Your help was invaluable.


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

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0