Web Analytics Made Easy -
StatCounter Old URL Redirect in HTACCESS - CodingForum

Announcement

Collapse
No announcement yet.

Old URL Redirect in HTACCESS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Old URL Redirect in HTACCESS

    I would appreciate a link to a previous post or a code snippet in regards to my issue. I have research this all over the internet and am about at the end of my rope! I would be so grateful for any and all assistance or guidance!

    I just migrated over my website from an old .asp site that used dynamic pages. I am now using a wordpress blog with market friendly URLs.

    I can get most of the straightforward redirects in the .htaccess file to work fine, but I'm running into the problem of linking the dynamic links. here are two separate examples below:

    I need to redirect:
    http://www.freetv.org/about/default.asp?ID=285
    to
    http://www.freetv.org/about/board-of-directors/

    or

    http://www.freetv.org/about/default.asp?ID=282
    to
    http://www.freetv.org/about/staff/


    Can somebody help me with the redirect code for this?

    Thank you, again, for your time in looking at this.

    Scott

  • #2
    Just curious

    Perhaps someone can help me out.

    No matter what forum I have posted this on or post that I have read (by other users) regarding this same topic, I have never seen one response. Plenty of people reading but noone saying anything.

    I guess I'm curious if this fits into one of the following categories:

    A) Impossible to do
    B) Taboo - Black hat - Highly unethical (I hope not. If so, I'm not interested)
    C) So basic it's frustrating
    D) Not many know how to do this.

    I am fairly new to programming and what I have read so far on SEO is to try and do a permanent 301 redirect on "dead urls" so that users don't run into 404 pages.

    Can someone give me a little education here? I don't mean to sound snide or cynical. I'm truly curious as to why this particular type of redirect seems to gather no interest.

    Thank you for taking time to read this.

    Scott

    Comment


    • #3
      There are a few ways you can do this
      • Mod_rewrite
        Code:
        Options +FollowSymLinks
        
        RewriteEngine On
        
        RewriteCond %{QUERY_STRING} ^(.*&)?[color=green]key=value[/color](&.*)?$ [NC]
        RewriteRule ^[color=green]file\.ext[/color]$ [color=green]/newurl[/color]? [R=301,L]
        The problem with this is that if there isn't a matchable relationship between the value and the /newurl then you need to repeat it for each one (unless you have access to the httpd.conf file, then you could use a RewriteMap).

      • A custom 404 ErrorDocument for .asp files
        Code:
        # Default 404 handler.
        ErrorDocument 404 /404handler.php
        # Match .asp files.
        <[url=http://httpd.apache.org/docs/2.2/mod/core.html#filesmatch]FilesMatch[/url] ".\.asp$">
          # .asp 404 handler.
          ErrorDocument 404 /asp404handler.php
        </FilesMatch>
      • A custom 404 ErrorDocument
        Code:
        ErrorDocument 404 /404handler.php

      Comment


      • #4
        Thank you so much for the response! I will give some of your code a try. I might be back with some questions, if you don't mind.

        Would I put that code verbatim into the .htaccess file or am I modifying the green text? I apologize for the simple questions, but I'm learning.

        If I modify, would you mind posting the code for the first example I gave and I can work through the others?

        I totally appreciate the help!

        Thanks again!
        Last edited by wildinspire; Apr 15, 2009, 05:10 PM.

        Comment


        • #5
          You modify it
          Code:
          Options +FollowSymLinks
          
          RewriteEngine On
          
          RewriteCond %{QUERY_STRING} ^(.*&)?ID=285(&.*)?$ [NC]
          RewriteRule ^about/default\.asp$ /about/board-of-directors/? [R=301,L]
          It is written to go in a .htaccess file in your document root.

          Comment


          • #6
            I will give that a try! Thank you so much for your assistance!

            Comment


            • #7
              I tried the code and it didn't work. I have pasted the code below. Everything works except for the redirect of: http://www.freetv.org/about/default.asp?ID=285


              # BEGIN WordPress
              <IfModule mod_rewrite.c>
              Options +FollowSymLinks
              RewriteEngine On
              RewriteBase /
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteRule . /index.php [L]
              </IfModule>

              # END WordPress

              Header unset ETag
              FileETag None

              <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
              Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
              </FilesMatch>

              RewriteCond %{HTTP_HOST} ^freetv.org [NC]
              RewriteRule ^(.*)$ http://www.freetv.org/$1 [L,R=301]

              Redirect 301 /find http://www.freetv.org/programs/
              Redirect 301 /default.asp http://www.freetv.org
              Redirect 301 /involved http://www.freetv.org/get-involved/
              Redirect 301 /events http://www.freetv.org/bulletin/
              Redirect 301 /playing http://www.freetv.org/programs/
              Redirect 301 /live.asp http://www.freetv.org/channel2/watch-live/

              RewriteCond %{QUERY_STRING} ^(.*&)?ID=285(&.*)?$ [NC]
              RewriteRule ^about/default\.asp$ /about/board-of-directors/? [R=301,L]

              Any thoughts?

              Comment


              • #8
                Try changing your last RewriteRule to RewriteRule about/default\.asp /about/board-of-directors/? [R=301,L].

                The "^" and "$" mean there can't be anything before or after "about/default\.asp" in order to match, but in your URL there clearly is.
                .My new Javascript tutorial site: http://reallifejs.com/
                .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
                .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

                Comment


                • #9
                  Thanks for the suggestion. I tried it and unfortunately it didn't work either. Not sure what I'm going to do at this point.

                  Comment


                  • #10
                    It has to run before the Wordpress "catch-all 404s"
                    Code:
                    FileETag None
                    Header unset ETag
                    Options +FollowSymLinks
                    
                    Redirect 301 /find http://www.freetv.org/programs/
                    Redirect 301 /default.asp http://www.freetv.org
                    Redirect 301 /involved http://www.freetv.org/get-involved/
                    Redirect 301 /events http://www.freetv.org/bulletin/
                    Redirect 301 /playing http://www.freetv.org/programs/
                    Redirect 301 /live.asp http://www.freetv.org/channel2/watch-live/
                    
                    <IfModule mod_rewrite.c>
                      RewriteEngine On
                    
                      RewriteCond %{QUERY_STRING} ^(.*&)?ID=285(&.*)?$ [NC]
                      RewriteRule ^about/default\.asp$ http://www.freetv.org/about/board-of-directors/? [R=301,L]
                    
                      RewriteCond %{HTTP_HOST} ^freetv\.org$ [NC]
                      RewriteRule ^(.*)$ http://www.freetv.org/$1 [R=301,L]
                    
                      # BEGIN WordPress
                      RewriteCond %{SCRIPT_FILENAME} !-f
                      RewriteCond %{SCRIPT_FILENAME} !-d
                      RewriteRule . /index.php [L]
                      # END WordPress
                    </IfModule>
                    
                    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
                      Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
                    </FilesMatch>

                    Comment


                    • #11
                      Schleppel, Thank You! That seemed to work! I am sorry for the late response. I have been working on some other projects. I really appreciate your help with this piece of my puzzle.

                      Take care, Scott

                      Comment

                      Working...
                      X