SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Impact of 'PrettyURLs'

    Hi,

    I am close from my completing my first database/PHP driven site. The last thing I am looking to do is to introduce 'pretty URLs' so look smart .com/products/red-widgets instead of .com/products?=red widgets.

    However I am confused as to what impact this may have. Do I still create the links as normal and they just appear different or do I need to write the links differently.

    Plus apparently Google dislikes query URLs.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    However I am confused as to what impact this may have. Do I still create the links as normal and they just appear different or do I need to write the links differently.
    Not sure what you mean...you have to use the "fancy" url in the link.

    Plus apparently Google dislikes query URLs.
    They don't care whether you use query strings or fancy urls makes no difference to google's search engine.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If you are going to go through the pain of learning how to handle "pretty urls" at the server level (using mod_rewrite) it makes sense to propagate the general adoption of these urls by generating internal "pretty url" links on your own site from the start.

    Leaving aside the arguments regarding SEO worthiness, pretty urls are also good because:

    you can read them out on the phone to people
    they look better in print
    they convey more meaning
    they are not ugly

    One of the biggest tricks is working out how to enforce uniqueness though.

  4. #4
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,888
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Plus apparently Google dislikes query URLs.
    Google is not mad keen on query URLs or static pages (and that includes pages created by a template/CMS using essentially static content), but it does want you to use query URLs for genuinely dynamic pages where the content is generated on-the-fly from a backend database in response to the query parameters.

    Google has no trouble at all in accessing, indexing and returning query URLs, but using query URLs for a static site, or vice versa, can have an adverse impact on how it understands your site. That is particularly true when you have multiple variables.

    eg if you have
    domain.com/search?product=redwidget&maxprice=1000&location=belgium
    Google knows that those three variables are independent and that the order is irrelevant (assuming it gets a 200 A-OK). So when it sees a link to
    domain.com/search?product=redwidget&location=belgium&maxprice=1000
    it knows that that is the same page that it has already got.

    But if you have
    domain.com/product/redwidget/maxprice/1000/location/belgium
    or even just
    domain.com/redwidget/1000/belgium
    it isn't obvious at all that those are query parameters (and in the first case variable names) that can be re-ordered or possibly removed. That means you're more likely to run into duplicate content issues and/or find that Google doesn't return the most relevant page from your site.

    A good way to combine the two features, if you do have genuine dynamic pages, is to have pretty URLs that visibly redirect to the real query URL. That way search engines know to use the query format and so can understand the structure better, but you're giving real people an easier route into the site.

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    Sounds much more complicated than I thought I would it be.

    I thought I just changed the HT Access file so when a I created products.php?=redwidget it automically rewrote it as /products/redwidget.

    What is the best way to do prettry URLS. Do I have to change all the links on my site.

    I am just at the stage of completing my site so I need to get it right!

    I found this.. http://www.nouveller.com/quick-tips/...with-htaccess/

    Is this a good way to do it?

  6. #6
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Editing the .htaccess file doesn't change any of the links on your pages; it only lets the computer understand them. Essentially, it "translates" the pretty links as the request comes in (when someone clicks the link) behind the scenes.

    The point is to give the end user a nice readable url. What you do on your server end is to have the server understand which file /products/redwidget is supposed to fetch. This can be done as shown in that post you linked to.
    - Robert

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    @Stevie D -- nice reply, thanks for taking the time to make that, very informative.

    @justlukeyou -- getting pretty urls from your database might lead you to turning a heading or a product title into something which is sometimes termed a "slug".

    Code:
    products
    ======
    id , title, slug
    ==========
    23 | Red Widgets | red-widgets
    Use advanced search constrained to this just this forum for the term slug to turn up some old discussions on this.

  8. #8
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Now im confused, if a database full of products what do I need to do it to introduce pretty URLs

  9. #9
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    a) a .htaccess rule which rewrites urls from /products/red-widget to products.php?item=red-widget

    b) a script called products.php which searches your database for "... from products where slug='red-widget'"

    OR

    if you do not go down the route of maintaining a unique slug that script uses the equivalent of:

    "from products where title = 'Red Widget'"

    which you can do using the likes of: "from products where title = '". str_replace("-", " ", ucwords($item)) ."'";

    For the sake of brevity the sql escaping is omitted, make sure you add it.

    The other way to achieve somewhat pretty urls is to keep the id number in the url as discussed a few days ago here.

  10. #10
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    As I am querying key words I cant use ID numbers. Option A sounds the easiest and most effective option.

    Is it possible to remove the "?=" and just replace it with a slash.

    Once I have sorted the links my site will be complete, frustrating to be stuck on this tbh lol

  11. #11
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    One of us is confused here.

    Using Apache's mod_rewrite takes a pretty url /products/red-widget and rewrites it that so behind the scenes this url is in fact fetched products.php?item=red-widget

    So, in reference my previous reply you do a) and then you go on and do b) in one fashion or another.

  12. #12
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    I have added this to my htaccess file

    However when I use /products/roomproductscategorised.php/bedroom instead of /products/roomproductscategorised.php?room=bedroom it doesn't work. However /products/roomproductscategorised.php?room=bedroom does work.


    RewriteEngine On
    RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]

    Im confused as to what rewrite code I use to make this work.

  13. #13
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Does anyone have any advise what I can do. I have managed to remove the .php and of links but I still cant create a link without a query in it.

    I cant progress with my site until this is sorted

  14. #14
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,198
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Off Topic:

    OK, thread moved to the Apache forum, where you will get more help with this issue from the likes of @dklynn ; and @ScallioXTX ;

  15. #15
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Thanks, Ralph!

    First, take a look at the menu items and links at http://wilderness-wally.com. Those links are the TITLE fields in a database which are unique, just like your digital ID numbers, but provide a "pretty" look as a URI. They are all served by a single file so the advice above is quite correct: YOU create the NEW FORMAT links in the manner you wish then YOU create the mod_rewrite code to convert that format to something Apache can serve. Wally's Home Page is titled Welcome so the link is http://wilderness-wally.com/Welcome. mod_rewrite converts that title to a value in a query string and passes that to the handler file (PHP) which fetches the content from the database.

    WARNING: You'll need to use non-reserved characters in the title - PM for the list I use at Wally's site.

    NOTE: I convert spaces to _'s before using the title as a link then convert back to spaces before querying the database.

    If you're take a look at the mod_rewrite tutorial linked in my signature, that should help you considerably. The bit about not using id numbers is rather buried in the immense amount of information but you'll be an expert after you read through it 3-4 times. Don't worry, though, there are plenty of coding examples!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •