SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Truncating Page URLs

    Hi there,

    I'm just working on a new design for my portfolio and would like some advice on how to remove the file extension from my pages (e.g. .asp, .html etc) and replace them with something more SEO-friendly (e.g. /portfolio.html to /website-design-portfolio).

    If anyone has any ideas how I could go about doing this I'd really appreciate it!

    Cheers,

    Shoxt3r.

  2. #2
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,881
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    If you add the line
    Code:
    Options +MultiViews
    to your .htaccess file, it will allow you to miss off file extensions. So if you ask for website.com/file and there’s a page at website.com/file.php it will redirect you to that. (If you have multiple files with the same name but different filetypes then this can go horribly pear-shaped and you would need to use a more rigorous re-write approach.)

    In terms of renaming the files, why would you want to replace a name that is short, easy to remember, easy to type and nicely tweetable, with one that is none of those? I really don’t get this current fetish for cramming half a paragraph into the URL, and I’ve not seen any real evidence that it makes a tangible difference to performance in search engines.

    But if you really feel you have to go down that route, you’ll need to set up individual re-writes for each file. If you use a CMS then it might have an option to do that, but otherwise it’s pretty straightforward. If you’re keeping the file name as it is now and just using the long name as an alias then for each page, just add a line like this to your .htaccess file:
    Code:
    Redirect 301 /fancy-long-new-url http://website.com/oldurl.php
    or if you’re going to actually rename the file to the new name you need it the other way round:
    Code:
    Redirect 301 /oldurl.php http://website.com/fancy-long-new-url
    Note that you need the full URL including http and domain name for the “to” part of the redirect, but not the “from” part.

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

    I consider MultiViews to be a major problem because it can pick a part of a filename out of a path and deliver unanticipated content. From Apache.org, there can be other problems (AddType and DirectoryIndex):

    Quote Originally Posted by http://httpd.apache.org/docs/2.2/content-negotiation.html
    Multiviews

    MultiViews is a per-directory option, meaning it can be set with an Options directive within a <Directory>, <Location> or <Files> section in httpd.conf, or (if AllowOverride is properly set) in .htaccess files. Note that Options All does not set MultiViews; you have to ask for it by name.

    The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

    MultiViews may also apply to searches for the file named by the DirectoryIndex directive, if the server is trying to index a directory. If the configuration files specify

    DirectoryIndex index

    then the server will arbitrate between index.html and index.html3 if both are present. If neither are present, and index.cgi is there, the server will run it.

    If one of the files found when reading the directory does not have an extension recognized by mod_mime to designate its Charset, Content-Type, Language, or Encoding, then the result depends on the setting of the MultiViewsMatch directive. This directive determines whether handlers, filters, and other extension types can participate in MultiViews negotiation.
    Shox,

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    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
  •