Forum Moderators: phranque

Message Too Old, No Replies

htaccess URL friendly

htaccess URL friendly

         

GregB

10:23 pm on Feb 15, 2010 (gmt 0)

10+ Year Member



I am having troubles getting the htaccess to properly pass friendly URL's:
Here is what I am trying to accomplish:

From:
mydomain.com/videos/ list all pages
mydomain.com/videos/cannes-film-festival-2008.php show the Cannes 2008 page
mydomain.com/videos/cannes/ list all the pages related to Cannes
mydomain.com/videos/cannes/cannes-film-festival-2008.php also show the Cannes 2008 page
To:
mydomain.com/videos/ list all pages
mydomain.com/videos/index.php?MUrl=cannes-film-festival-2008 show the Cannes 2008 page
mydomain.com/videos/index.php?location=cannes list all pages related to Cannes
mydomain.com/videos/index.php?location=cannes&MUrl=cannes-film-festival-2008 also show the Cannes 2008 page

Using the following htaccess I get an Internal Server Error on Apache version 2.2.14 (Unix)
It works perfectly on my Mac OS X 10
The htaccess is located in /videos/

RewriteEngine on
Options +FollowSymLinks
# RewriteBase /videos/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^/\.\?]+)/?$ index.php?Location=$1 [L,NC]
RewriteRule ^([^/\.]+)/(.+).php index.php?Location=$1&MUrl=$2 [L,NC]
RewriteRule ^(.+)\.php ?MUrl=$1 [L,NC]


Any Suggestion?

jdMorgan

12:19 am on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This looks like a bit of a mess -- rife with possibilities for duplicate-content problems.

Can you clarify:

  • What one "friendly" URL of each type do you prefer? (You must make sure your site links only to this URL. To be clear you must not allow both mydomain.com/videos/cannes-film-festival-2008.php and mmydomain.com/videos/cannes/cannes-film-festival-2008.php to both directly show the Cannes 2008 page: One must 301-redirect to the other, and the one that does not redirect will be rewritten to the script.)

  • What is the script filepath and query string associated with each of these types of "friendly" URL?

    Jim
  • GregB

    3:07 am on Feb 16, 2010 (gmt 0)

    10+ Year Member



    Hello Jim,
    Thank you for looking into this...

    I have, a list of all the videos that can be played on that same page.
    www.nikkivideos.com/videos/
    But I also have those videos by their locations for example Cannes
    www.nikkivideos.com/videos/cannes/ which is the same as www.mynikkibeach.com/videos/?Location=12

    You can play the same video in both places:
    www.nikkivideos.com/videos/?MediaID=553
    www.nikkivideos.com/videos/cannes/?MediaID=553


    Each directories under videos /"locations name"/ have the following index page with the corespoinding Location number.
    <?php
    $Location="12";
    require_once($_SERVER["DOCUMENT_ROOT"].'/videos/index.php');
    ?>
    As you can see I am really only using one php page and a bunch of subdirectories.

    In my Database I have a unique ID (MediaID=553) and URL name (nikki-beach-cannes-film-festival-part-1) and locationID (Location="12") for each entries.

    All I am trying to do is be able to have the following without having to create a directory for each locations.
    www.nikkivideos.com/videos/nikki-beach-cannes-film-festival-part-1.php
    and
    www.nikkivideos.com/videos/cannes/nikki-beach-cannes-film-festival-part-1.php

    Hope this makes more sense.

    Let me know what you think.

    GregB

    3:18 am on Feb 16, 2010 (gmt 0)

    10+ Year Member



    I forgot to say that the LoctionID can also be the name:
    www.mynikkibeach.com/videos/?Location=12
    same as
    www.mynikkibeach.com/videos/?Location=cannes

    Greg

    jdMorgan

    4:02 pm on Feb 16, 2010 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Because it has no built-in database access, mod_rewrite doesn't have any good method to "associate" the location value "12" with "Cannes." And as noted in my previous post, you have a bit of a mess with some serious canonicalization problems with your URLs.

    So my suggestion in this case is to get rid of all of the per-location php scripts (like the one at /cannes/index.php you gave as an example two posts above), and simply rewrite all /videos URL requests straight from those URLs to the main index.php script in your /videos directory. Modify that script to take either the "location=" parameter or the "mediaID=" parameter from the query string (if present in dynamic URLs), or to take the "venue name" from the static URLs (if present). In all but the latter case, look up the query string data, convert it to the static URL-format, and issue a 301-Moved Permanently redirect to the now-canonical static/friendly URL. The php "preg_replace" function is great for this kind of thing, as long as you are very careful to get the regular-expressions pattern used for URL matching exactly-right.

    In the case of the static/friendly URLs like /videos/nikki-beach-cannes-film-festival-part-1.php
    versus
    /videos/cannes/nikki-beach-cannes-film-festival-part-1.php,
    pick one of those formats, and 301-redirect the other format to this chosen format. (I suggest you consider maintenance, duplicate-content avoidance, and the small keyword-in-URL SEO and click-through benefits factors when making this decision).

    Then link only to the single canonical static/friendly URL for each 'page' or 'video' from within your own pages.

    Seeing a 301-redirect response from your server (which ends the current HTTP transaction), the client will then 'come back' with a new HTTP request using the canonical static/friendly URL provided in that redirect response, which will once again get rewritten to your (single) script, which will then 'see' that this URL is canonical, and serve the requested content.

    This solution accomplishes several things:
  • It centralizes maintenance and management by eliminating the need to have one php script per location.
  • It improves performance by eliminating the need for those per-location scripts to 'include' the main script (an additional disk read per page request).
  • It eliminates PageRank/link-popularity dilution and the resultant ranking problems brought about by duplicate-content. When implemented, each video on your site will be directly available only from the single canonical static/friendly URL; All variations --to include dynamic URLs, non-canonical hostnames, FQDN-format hostnames, port numbers appended to hostnames, and mis-cased or redundant URLs will be 301-redirected to the one and only URL that is allowed to access the content.
  • It moves the 'heavy-lifting' into php, which I presume is a more comfortable environment for you, and which also gives the ability to access the database to get the information needed to sort out the non-canonical URL problems.

    The RewriteRule in this case then becomes trivial:

    RewriteCond $1 !^/index\.php$
    RewriteRule ^videos(/.*)?$ /videos/index.php [L]

    The script itself can then query server parameters to 'get' the originally-requested URL and use it as described above.

    Jim
  • GregB

    7:41 pm on Feb 16, 2010 (gmt 0)

    10+ Year Member



    Thank you Jim for taking the time to respond in such detail.
    I will definitely follow you solution. Just need to find the time to do it:)
    Again thank you

    Greg