8 Replies - 881 Views - Last Post: 03 October 2009 - 02:51 PM

#1 Optics  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-October 09

Need help organizing my website URL's

Posted 03 October 2009 - 11:11 AM

Hi,

I'm currently creating a small blog website with PHP and MySql. Essentially, I have a page called news.php, which displays articles from a MySql database. If you click on the title of any article, news.php will re-organize itself with a ?article=article1 tag in the URL telling the php script to display the full body text of article 1 on the page.

The url: www.DomainName.com/news.php?article=article1 however looks fairly ugly. I've seen plenty of websites with a similar system using this type of URL instead: www.DomainName/com/news/article1. How do I make my URL like that? Is it with php, or something else?

Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: Need help organizing my website URL's

#2 capty99  Icon User is offline

  • i am colt mccoy
  • member icon

Reputation: 97
  • View blog
  • Posts: 10,081
  • Joined: 26-April 01

Re: Need help organizing my website URL's

Posted 03 October 2009 - 11:28 AM

forgive me my knowledge is low here, but i have diddled around with a few frameworks and so i'm pretty sure what your looking for is
a model view controller that will handle that.

again, knowledge is low, but i would read up on a framework, or just model view controller in general since its used in a bunch of programming languages. YES, there is a php way to do it, but you probably would have to start from the ground up (code wise) to do it. Someone else will probably have more info than me
Was This Post Helpful? 0
  • +
  • -

#3 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 204
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: Need help organizing my website URL's

Posted 03 October 2009 - 11:32 AM

the design pattern is useful and you could do it with MVC to redirect the page when ever a get variable is supplied, but a more professional url rewrite could be done using .htaccess as well.

If you want leave the get variables in the URL you could always adjust it so it is a little neater, something like ?article=1
Was This Post Helpful? 0
  • +
  • -

#4 capty99  Icon User is offline

  • i am colt mccoy
  • member icon

Reputation: 97
  • View blog
  • Posts: 10,081
  • Joined: 26-April 01

Re: Need help organizing my website URL's

Posted 03 October 2009 - 11:45 AM

YES I WAS RIGHT. (if you have short titles or wanted to add a new field to the db, you could point to the page title) so ?article=new_dinosaur_found

or something like that.... but thats not as clean
Was This Post Helpful? 0
  • +
  • -

#5 Optics  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-October 09

Re: Need help organizing my website URL's

Posted 03 October 2009 - 11:58 AM

If I were to do it with a redirect, where would it be re-directing the user to? If this were the case, wouldn't I need a directory for every single news article? (Which seems awfully wasteful.)
Was This Post Helpful? 0
  • +
  • -

#6 Trilation  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 13-May 06

Re: Need help organizing my website URL's

Posted 03 October 2009 - 12:07 PM

Optics, from your information I believe you are referring to [SEO]"friendly" URLs.

These URLs redirect pages such as index.php?article=5103&tag=55 to a more readable URL. Thus it is used by many websites and is an option you can enable in popular blog platforms like Wordpress.

The most common method for achieving this is through the Apache .htacess Mod_Rewrite extension.

You can read more about .htacess and mod_rewrite here:
http://corz.org/serv...s/htaccess2.php

I hope this helps you achieve what you want to do.
Was This Post Helpful? 0
  • +
  • -

#7 Optics  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-October 09

Re: Need help organizing my website URL's

Posted 03 October 2009 - 12:51 PM

View PostTrilation, on 3 Oct, 2009 - 11:07 AM, said:

Optics, from your information I believe you are referring to [SEO]"friendly" URLs.

These URLs redirect pages such as index.php?article=5103&tag=55 to a more readable URL. Thus it is used by many websites and is an option you can enable in popular blog platforms like Wordpress.

The most common method for achieving this is through the Apache .htacess Mod_Rewrite extension.

You can read more about .htacess and mod_rewrite here:
http://corz.org/serv...s/htaccess2.php

I hope this helps you achieve what you want to do.


Yes, that's exactly what I'm thinking of, however the link you provided confused the crap out of me. Do you have a "for dummies" version?
Was This Post Helpful? 0
  • +
  • -

#8 Trilation  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 13-May 06

Re: Need help organizing my website URL's

Posted 03 October 2009 - 02:35 PM

Mod_Rewrite is one of the most complex extensions of Apache. Although it is intimidating, it is one of the most powerful extensions for Apache especially for what you are trying to do.

I wasn't able to find anything similar to a dummies guide, but I recommend you start from the intro http://corz.org/serv...ks/htaccess.php and try to work your way through. There are several links at the bottom of part two to try and help you understand.

Maybe another user could find a better guide.

I hope you're able to accomplish what you want, good luck!
Was This Post Helpful? 0
  • +
  • -

#9 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Need help organizing my website URL's

Posted 03 October 2009 - 02:51 PM

Quote

How do I make my URL like that?
You don't make the URL. The client does. I'm sitting at my computer, and I decide what I want to type.

Let's say your website is at example.com. I type into my browser, www.example.com/completely/random/words . The question isn't forming this URL. I just did that. The question is, how does your server handle this URL?

The direction you are being told about here is to rewrite the URL. So, that HTTP request (which is sent when you hit "go" in the browser) is picked up by Apache. You instruct Apache to transform URLs with a set of rules, so perhaps your rules craft the rewritten URL www.example.com/completely.php?cata=random&catb=words . Then Apache passes this URL into the chain of handlers and modifiers in its design. Somewhere at the end, you have a PHP program that pick up that URL and works with it.

But here's the key. Handling URLS isn't about rewriting. It's about handling them. With PHP, you need to receive URLs of the form /folder/subfolder/subsubfolder/page.php . Requests needs to be handled by interpreting a certain page. Thus, you must configure Apache to transform all URLs into this format, otherwise your PHP application cannot handle them.

If you had an application that didn't have this constraint, for example, you wouldn't need to configure Apache with mod_rewrite. For example, I tend to build sites with Python, and that means an application server mindset. My Python application server can handle that URL directly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1