SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Htaccess - Help redirecting to new URLs

    I'm trying to do a URL rewrite and redirect

    Currently I have the following URLs:
    http://parttimejobsin.us/cities/index.php?id=1
    http://parttimejobsin.us/cities/index.php?var=Accounting&id=1

    In order to rewrite them I used the following code for the .htaccess file:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^cities/([^/\.]+).html?$ cities/index.php?id=$1[L]
    RewriteRule ^cities/([^/\.]+)/([^/\.]+).html?$ cities/index.php?var=$1&id=$2 [L]
    That has worked fine for rewriting. However, I now want to 301 redirect the old URLs to the newly rewritten URLs so that there won't be duplicate content on my site.

    In other words, if a user types in:
    http://parttimejobsin.us/cities/index.php?id=1
    I would like them to be automatically 301 redirected to:
    http://parttimejobsin.us/cities/1.html

    Additionally, if a user types in:
    http://parttimejobsin.us/cities/index.php?var=Accounting&id=1
    I would like them to be automatically 301 redirected to:
    http://parttimejobsin.us/cities/Accounting/1.html

    Is this possible to do? Any help would be greatly appreciated!
    Last edited by ScallioXTX; Sep 23, 2010 at 03:31. Reason: De-linkified URLs for better readability

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,075
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    You sure can. Take a look at the section "Redirect TO New Format" of the article on mod_rewrite written by SitePoint member dklynn:
    http://datakoncepts.com/seo#example-12
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I'll try that.


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
  •