php id for url instead of massive url link?

Soldato
Joined
7 Jan 2007
Posts
10,607
Location
Sussex, UK
Hi,

I'm very much a beginner of PHP but I have noticed some sites have done there internal links like this:

href="http://www.oxy.co.uk/oxy.php?p=100

Now, I think they have created a php file called oxy.php which contains a list of links with an id number, in this case 100 so when it checks oxy.php it knows to travel to the link with an id=100.


Have I understood it right?

How on earth do I go about setting this up for my site? Any guides out there for this? What's this technique even called?

I'm really new to php and all comp language so I really would appreciate peoples input.
 
The GET variable would typically be used by the PHP to pull an article out of a database. The page ID would generally correspond to the ID in the database.

Watch out for SQL injection - write your code from the beginning with this in mind.

These days, people are looking to use 'SEO friendly' URLs - which means not using a page ID or similar abstract concept in the address bar, but something like

yoursite.com/category/page-name

Which would be achieved with some clever mod_rewrite rules and logic in your code.
 
Google prefer that you use static and clear URLs like www.mysite.com/mypage-somethinghere.html rather than mypage.php?id=100. If the page is very dynamic and relies heavily on user input like this forum then you're better of sticking to having variables in the URL. There's nothing wrong technically with pages made this way it's just to make it look all nice and tidy.
 
Avoid variables in urls unless you have to. It's better practice for reasons stated above.

From Google SEO PDF

Create a simple directory structure
Use a directory structure that organizes your content well and makes it easy for visitors to know where they're at on your site. Try using your directory structure to indicate the type of content found at that URL.
Avoid:
  • having deep nesting of subdirectories like".../dir1/dir/dir/dir4/dir5/dir6/page.html"
  • using directory names that have no relation to the content in them

Use Words in Urls

URLs with words that are relevant to your site's content and structure are friendlier for visitors
navigating your site. Visitors remember them better and might be more willing to link to them.

Avoid:
  • using lengthy URLs with unnecessary parameters and session IDs
  • choosing generic page names like "page1.html"
  • using excessive keywords like"baseball-cards-baseball-cards-baseballcards.htm"
 
Back
Top Bottom