Results 1 to 3 of 3
  1. #1

    Need help redirecting old links to new links

    How can I do this using htaccess?

    My old site used links such as:

    domain.com/this+is+a+page

    I want to redirect to the new site structure (uses underscores and ends in .html):

    domain.com/this_is_a_page.html

    However I do not want to redirect domain.com/admin
    GlumboUploads - File hosting without wait-times or CAPTCHAs
    RichPeopleThings - Blog about rich people and luxury items

  2. #2
    Join Date
    Jul 2005
    Posts
    55
    .htaccess supports mod_rewrite rules (if Apache has that module loaded). You will be able to do any of these things that you want using mod_rewrite rules.

    It's a bit of a bear to learn the syntax, but there are plenty of tutorials for doing anything you can imagine with mod_rewrite.

  3. #3
    Join Date
    Mar 2007
    Location
    UK
    Posts
    89
    I'm a bit rusty with my rewrite rules, so someone may be able to improve upon this, but it works:
    Code:
    RewriteEngine On
    RewriteBase /
    
    # rewrites /meh+hi+there to /meh_hi_there.html
    # replaces all + with _
    #     ignores directories
    #     ignores URIs that end with .*
    #     ignores /admin
    
    RewriteCond %{REQUEST_URI} !^/admin$ [NC] # ignore /admin 
    RewriteCond %{REQUEST_FILENAME} !-d  [NC] # ignore directories
    RewriteRule (.*)\+(.*) $1_$2 [N,R=302,L]  # replace all + characters with _
    
    RewriteCond %{REQUEST_URI} !^/admin$ [NC] # ignore /admin 
    RewriteCond %{REQUEST_URI} !\..*$ [NC]    # ignore anything that already has a file extension (eg .html)
    RewriteCond %{REQUEST_FILENAME} !-d  [NC] # ignore directories
    RewriteRule ^(.*)$ /$1\.html [R=301]      # append .html
    HTH,

    Simon

Similar Threads

  1. Replies: 0
    Last Post: 04-15-2009, 03:49 PM
  2. Replies: 1
    Last Post: 12-28-2008, 03:23 AM
  3. Replies: 1
    Last Post: 11-16-2006, 01:59 PM
  4. Replies: 3
    Last Post: 03-13-2005, 12:17 PM
  5. Replies: 2
    Last Post: 01-01-2005, 10:38 PM

Posting Permissions

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