NoobDev4iPhone
NoobDev4iPhone

Reputation: 5729

Custom link for each user in PHP

The standard GET query as a link for each user is easy but ugly for the users and search engines.

// This looks UGLY
website.com/index.php?userid=43232

//This is what I want
website.com/coolUser

How to make a custom link for every user without creating folders all the time?

Upvotes: 0

Views: 279

Answers (3)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230286

It's called "routing". Read this article for more.

Upvotes: 3

Zul
Zul

Reputation: 3608

Simple way to make URL like that, using .htaccess (create .htaccess file and upload to your public_html / wwwdir)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?userid=$1 [L]

Now, you can access http://yoursite.com/43232 OR http://yoursite.com/index.php?userid=43232

Upvotes: 0

Mohammad Saberi
Mohammad Saberi

Reputation: 13166

What you mentioned called "clean URL", and what you need something known as "mod-rewrite" capability in Apache configuration.

Sergei and Zulkhaery direct you to it with their comments. Also you can take a look at the link below: http://wettone.com/code/clean-urls

But don't forget you may see some problems with you css, js, and image files. But they have their own solutions too. You can find them if you get these problems.

Upvotes: 1

Related Questions