#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Rewrite URLs to be SEO Friendly


    Looking for advice on how to properly rename the URLs on my website to be SEO friendly. The website is PHP with an .htaccess folder in the admin panel. I'm not a PHP guru, but I know a little about editing code.

    I'd like to use the best method that is SEO friendly.

    Any suggestions?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0
    The best way is using dash separated keywords like

    category-name/current-page-title
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    98
    Rep Power
    3
    • Keep your rewritten URL's directories to a maximum of 2-3 for SEO (i.e.. example.com/dir1/dir2
    • You can appened .html to the end of your main pages (i.e.. example.com/dir1/final_destination.html)
    • Use Keywords in your URLs, that are also present in your content. (i.e.. example.com/articles/article-or-news-title.html)
    • Use dashes in your URL's and not underscores. Search engines recognize dashes as spaces
    • Keep your directories in your URL's open without a trailing slash for pages that just lead to yet another page (i.e.. example.com/category1/morecategoriesafter
    • Follow a consistent URL naming scheme throughout your entire site. Break out the pad of paper and pencil and design a naming scheme that you can follow. Plan, prepare, execute.


    Also, I think this thread would do better in the Search Engine Optimization section of this forum.
    Last edited by BitZoid; January 23rd, 2013 at 05:25 PM.
    -- Success achieved from tribulation --
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0
    Thanks for the advice, but I need to understand how to do the rewrite properly.

    1. Would I use the following code to 301 w.cityofficespaces.com/default to w.cityofficespaces.com ?

    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^w.cityofficespaces.com/default [nc]
    rewriterule ^(.*)$ w.cityofficespaces.com/$1 [r=301,nc]

    2. How would I rewrite w.cityofficespaces.com/Search/SearchDetails/24 to become w.cityofficespaces.com/office-space-for-rent-new-york-city/midtown-west/24 ?

    Thanks,
    David
  8. #5
  9. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124
    One issue many newbies to .htaccess rewritning stumble on is this:

    .htaccess and php don't talk to each other, so just adding URL rewriting to .haccess does not automagically rewrite the outgoing html - you have to do this in your templates.

    .htaccess rewriting is for rewriting the incoming requests from a request that does not match a file to a request that does match a file

    eg when a user requests

    http://www.example.com/friendly/link.html

    then the server actually gets

    http://www.example.com/index.php?q=friendly/link.html

    (for example)

    This can be achieved with

    Code:
    #turn on rewrite engine
    
    RewriteEngine On
    
    #operate on web root
    
    RewriteBase /
    
    
    #if the request is not an existing file, continue
    
    RewriteCond %{REQUEST_FILENAME} !-f
    
    
    #if the request is not an existing directory, continue
    
    RewriteCond %{REQUEST_FILENAME} !-d
    
    #do a rewrite.The L option means that no further rules should be processed after this one, if this one executes
    
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    
    #(can't remember what the QSA options are about;) )
    your templates would then need to make the links to

    http://www.example.com/friendly/link.html

    instead of

    http://www.example.com/index.php?page_id=8
    Last edited by Northie; January 24th, 2013 at 12:28 PM. Reason: additional code and comments
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,232
    Rep Power
    9400
    Originally Posted by BitZoid
    Also, I think this thread would do better in the Search Engine Optimization section of this forum.
    Back when we thought he wanted advice about what they should look like, yes, but since the question is apparently about how to do it this thread here is fine.

    Comments on this post

    • BitZoid agrees : Agree

IMN logo majestic logo threadwatch logo seochat tools logo