How can I make text appear in url instead of numbers ?

So basically what I am asking is how to make a link like this
example.com/word-text-goes-here
and how to use it like I would with
example.com/example?=1,2

How to make text appear in url and receive numbers like 1,2 ?

That’s done in your .htaccess file using mod rewrite.

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

You can find a lot of examples on the web that explains how to do this…

Br1ck, are you asking to have the URL look different in the displayed address in your browser?
If so, review Topcoder’s answer…

Are you saying you want to place a link in your HTML that can send the user to a page with arguments in place?
If so, you just do it like this:

word-text-goes-here
If on your own server, it would not need the example.com
And, in the receiving page, it would read the variables using $arg1=$_GET[“variablename1”] etc…
If this is your question, you can plug in values from PHP variables into the link. Not really sure of the question.

This question has two parts

How to get the “pretty” urls:
Follow the htaccess advise above.

How to get the text in the url:
Usually you store a sluggify/create a slug of the text, which means you “translate” ie “De To Tårn” to “de-to-tarn”.

So you might have a db schema like this

id | title | slug | description | other

Then you can just

[php]SELECT * FROM yourtable WHERE slug = ?[/php]

Or you could have both the id and the slug in the url, ie:
example.com/blog/1/testing-the-new-nsx
example.com/blog/1-testing-the-new-nsx
etc…

You can find lots of examples (and packages) online that will “sluggify” text for you.

ie: https://github.com/cocur/slugify

[php]use Cocur\Slugify\Slugify;

$slugify = new Slugify();
echo $slugify->slugify(‘Hello World!’); // hello-world[/php]

Thank you all for the answers,much appreciated.

Sponsor our Newsletter | Privacy Policy | Terms of Service