2

The Scenario

Soooo many questions on this topic but I still don't get it. So I apologize.
So, You've certainly urls like this : Cool Urls

the second img

Since, I'm self taught, these cool looking urls always confuse me. You see that the article heading words are separated by a hyphen. Looks neat and all. Also, you can see that there is no .php or .html (or any other technology used) extension.

The question

I also want to format my urls like this... For example : to get the post on my blog, I use post_id via GET to get the post from the database.. the current url structure looks like this : enter image description here

Can I get this url to be formatted something like this?

candhblog.base.pk/article/2
// or something like this :
candhblog.base.pk/article/my-favorite-country

I've seen many questions like this and solutions like "edit the .htaccess file" or using "RewriteEngine" but, I want to know how this works. How to create your urls as to include the article heading (for my example). Do I need to create folders? Please be comprehensive :)

candh
  • 238
  • 2
  • 13

1 Answers1

1

You can use .htaccess to redirect all requests to php file and manage thous via php in very easy way. Redirect all to index.php htaccess

If You use this way ,You don't need to create any folders based on your urls. You must get only path like this :

$path = $_GET['path'];

and explode $path by '/' and manage all of separated parts.

For your purpose i suggest you to use both id and title in your URL like this:

candhblog.base.pk/article/2/my-favorite-country

and after separate URL , you can get id of your post.

although another way is pass only title in URL like your example :

candhblog.base.pk/article/my-favorite-country

for SEO and user friendly but it needs to be your title unique.

The easiest and best way based on my experience is keeping only id in URL for minifying and using canonical meta tag in your html output for seo like this: URL: candhblog.base.pk/article/2 and meta: <link rel='canonical' href='http://candhblog.base.pk/article/my-favorite-country' />

Community
  • 1
  • 1
Vahid Moradi
  • 791
  • 7
  • 16
  • 1
    A link to a potential solution is always welcome, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. – davejal Dec 05 '15 at 11:26
  • I also need to know how can I import a article by it's heading and how to convert the post heading with hyphens in it. Please Help, I'm completely lost... – candh Dec 05 '15 at 16:43
  • Okay, @viam. I think I've figured out these semantic URLs. I have only one more question, please help. How to get these titles with hyphens in the address bar? Will I still recognize the post by its id ? (which is the right thing) even if its not coming from the address bar!? – candh Dec 06 '15 at 12:20