Simon
Simon

Reputation: 1

.htaccess - shorten url string

I'ld like to shorten this link. I think .htaccess is the solution fo this, right?

http://www.example.com/myfolder/?option1=hello&name=world&land=how&location=are&city=you

How can this be managed? Thanks

Upvotes: 0

Views: 561

Answers (1)

Alex Angelico
Alex Angelico

Reputation: 4045

I think what you want to achive is this

http://www.example.com/hello/world/ => http://www.example.com/myfolder/?option1=hello&name=world&land=how&location=are&city=you

right?

If so, you can use htaccess like this:

RewriteEngine on
RewriteRule ^([a-zA-Z-_0-9]*)?\/([a-zA-Z-_0-9]*)\/?$  /app/index.php?option1=$1&name=$2

The use is somehow complicated, but the idea is:

if somebody open the URL: http://www.example.com/first/second/

the first: ([a-zA-Z-_0-9]*) 'captures' the word 'first'

the second: ([a-zA-Z-_0-9]*) 'captures' the word 'second'

and then converts to /app/index.php?option1=first&name=second

Check this article for more info http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html

I'm using [a-zA-Z-_0-9] because the url can contain letters, numbers and underscore. You can select the characters you want.

Upvotes: 1

Related Questions