FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


URL shorten - HELP





Sash117
Dear All,

I need help to make my long url shorten, it would be nice to achieve this by htaccess file.

Let me start: How my url looks like now:

http://www.mysite.co.uk/iframeshow.php?lang=php&site=mysite.co.uk&options=o&hs=galaxynote3black

The hs=galaxynote3black is dynamic and it changes depands which mobile phone you are looking. Its looks like this: hs=<?php echo $_GET["hs"];?>

What i want is to see the url like this: http://www.mysite.co.uk/galaxynote3black

Can anyone help please?

my htaccess file currently look like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Thanks
Peterssidan
I think you can do what you want by adding this line of code to your .htaccess file.
Code:
RewriteRule ^(.*)$ iframeshow.php?lang=php&site=mysite.co.uk&options=o&hs=$1 [L]


Are all those parameters really necessary?
Marcuzzo
I'm not sure that a htaccess only solution will help here, I've had little experience with htaccess so I'm not sure if it will do the trick.

if you look at Codeigniter, they use the htaccess file to send everything to their core for routing using this:

basic htaccess file:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]


what you could do next is get all the needed info from the _GET and _SERVER['REQUEST_URI_PATH'] and work with that:

Code:
<?php

if ( ! empty( $_GET))
{
    echo '<h3>Getting _GET data</h3>';
    foreach ($_GET as $key => $value)
        echo '<p>' . $key . ': ' . $value . '</p>';
}


$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$segments = explode('/', $_SERVER['REQUEST_URI_PATH']);

if ( ! empty( $segments))
{
    echo '<h3>Getting Segments</h3>';
    foreach ($segments as $key => $value)
        echo '<p>' . $key . ': ' . $value . '</p>';
}



entering the following url:
Code:
http://testing.local/galaxynote3black?t=ok&a=b

(I've got a local virtual test server running as testing.local)

you will get the following output:

Code:
Getting _GET data

t: ok

a: b

Getting Segments

0:

1: galaxynote3black


hope this helps
codersfriend
You will just need to understand regular expressions which are a bit hard to learn at first
Related topics
cron jobs
Easy way to do sidepanel links?
Need help with Java
add to favorites script
Mambo tutorial
ImageShack's Tools
URL Redirection Error?
How to install php nuke? [can be closed for now]
Wordpess help needed.
SUSE and Ubuntu
Php as text and short urls.
HELP!!!
HELP !!!
They pulled the plug on the Halo Movie! Help it back!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.