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


Shortened URL path in php





vickriz
Hi,

Is there a way to accomplish in the address bar to show only the short url of a link?
Example:
the full url path:
http://mamuco.com/gallery/view_album.php?set_albumName=Bicycle
the shorten one:
http://mamuco.com/gallery/bicycle

how to do this using php script?


Thanks,

Vickriz
alalex
You can't do that using a php script, but you can do it using .htaccess and mod_rewrite.
I'll show you how to do it here:
First of all create a new text file in the folder gallery/ and call it htaccess.
Open it and paste the following lines:
Code:
# this is the initialization
Options         +FollowSymLinks
RewriteEngine   On

# these are the rewrite conditions
RewriteCond     %{REQUEST_FILENAME}     !-f
RewriteCond     %{REQUEST_FILENAME}     !-d

# and finally, the rewrite rules
RewriteRule     ^([a-zA-Z0-9\-]+)/?$    /view_album.php?set_albumName=$1 [L,QSA]


This way all requests send to gallery/whatever will be sent to:
gallery/view_album.php?set_albumName=whatever Wink
polly-gone
Well, you could make a script at the shortened URL that redirects it to the long one.

EDIT: -Nick Cool Cool Cool
vickriz
polly-gone wrote:
Well, you could make a script at the shortened URL that redirects it to the long one.

EDIT: -Nick Cool Cool Cool


Hi,

The long URL should be redirect to the short one. Right now I'm still puzzle with this redirection code.
polly-gone
Try this:

Code:
header('Location: www.example.com');


That redirects it. Note: You cannot have any output before this.

-Nick Smile Smile Smile
James007
Please follow alalex' method. Php redirects aren't made to address your needs. If you like this folder-like structure, you need to use a mod rewrite.
mathiaus
vickriz wrote:
The long URL should be redirect to the short one. Right now I'm still puzzle with this redirection code.


Give us an example of what your 'long' URL will look like, and what you want your new 'short' URL to be.
moejoe
Hey,

I found this:

works 100%, You just need to make sure that you install it to your .htaccess file (Go thru Cpanel to find it)

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /view_album.php?set_albumName=$1 [R]


Best wishes[/quote]
Related topics
script backup database
site colse/open with php
VBulletin Portal Installing
snow?
How do I make a simple slideshow?(RESOLVED)
Getting a URL with PHP
Redirect
PHP - Error
Can I Change My Subdomain Path ?
Switching Hosts, help me!
Select a url for an image in image functions
PHP script problem
URL Parameters PHP
removing DirectAdmin part of URL makes php code work
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.