Is it possible to shorten a url without using htaccess file?
for example I have this url.
this/is/a/very/long/url.php
change to
short/url.php
I hope I can get good answer THX guys:)
Is it possible to shorten a url without using htaccess file?
for example I have this url.
this/is/a/very/long/url.php
change to
short/url.php
I hope I can get good answer THX guys:)
You must be logged in to post a comment.
yes, mostly used in frameworks
an approach called using a front controller
ex: your front controller is index.php
your page links are generated as a fashion of …/index.php/nything/url.php
but the actual link is …/this/is/long/url.php
the front controller extract the page information the client requested and show the relevant page related to it
read more : http://en.wikipedia.org/wiki/Front_Controller_pattern
This is a good question, there are multiple options however the .htaccess file is probably your best bet.
this SO post describes it
Handling the url rewriting serverside is key here since it will be much faster to execute and will not break your script when used on some URL’s.
so http://www.yourdomain.com/test/4/twenty/long/url/could/be/shorter/
all the arguments after http://www.yourdomain.com, can be retrieved via various PHP methods, including reading up on PHP’s
$_SERVER
would be a good idea, as lots of variables are placed in that global array.mod_rewrite
is part of Apache, so it needs to be configured in Apache config..htaccess
actually Apache “live” config “per directory”.In general the best way ( I think) to rewrite urls is to rewrite everything to one file, let’s say
index.php
and then “redirect” to specific file basing on URL. You can read a lot about “URL routing” in PHP on the web.You can use this code in Javascript for rewriting current URL: