SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2007
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Redirect from ASPX to Wordpress

    I am trying to redirect http://theitinerantgolfer.com/Courses.aspx?ID=218 to http://theitinerantgolfer.com/pinehu...t-no-2-course/

    I have around 100 golf course posts to redirect so any help would be appreciated.

    My permalinks are set up as: /%postname%/

    So far I have had my htaccess file set up the following ways, but I keep getting a 404 page.

    RewriteEngine On
    RewriteRule ^(.+)\.aspx?$ $1.php [L]

    RewriteCond %{HTTP_HOST} =theitinerantgolfer.com/Courses.aspx
    RewriteCond %{QUERY_STRING} =id=218
    RewriteRule ^default\.asp$ http://theitinerantgolfer.com/pinehu...t-no-2-course/ [NC,L,R=301]

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




    RewriteCond %{HTTP_HOST} =theitinerantgolfer.com/Courses.aspx
    RewriteCond %{QUERY_STRING} =id=218
    RewriteRule ^default\.asp$ http://theitinerantgolfer.com/pinehu...t-no-2-course/ [NC,L,R=301]

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




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

    Redirect 301 /Courses.aspx?ID=218 http://theitinerantgolfer.com/pinehu...t-no-2-course/

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

    Seriously? Is your aspx website hosted on an Apache server or did you just move your domain to Apache?

    Okay, believing that it must be the latter situation, where is Apache supposed to get "pinehurst-resort-no-2-course" from? Because mod_rewrite does not have access to a database (at least most webmasters won't), you'll not be able to translate ID=218 directly to pine... What you're asking for is either the RewriteMap (which is only available via httpd.conf or httpd-vhosts.conf) or using a handler script to do the database lookup for you then redirect to pine... In either case, I believe you need to study mod_rewrite a bit before proceeding (you can start with the link in my signature).

    Saying that, you should not get a 404 on redirecting Courses.aspx to Courses.php unless Courses.php does not exist.

    WARNING TO OTHERS: Do NOT use code like this!
    Code:
    RewriteEngine On
    RewriteRule ^(.+)\.aspx?$ $1.php [L]
    
    RewriteCond %{HTTP_HOST} =theitinerantgolfer.com/Courses\.aspx
    RewriteCond %{QUERY_STRING} =id=218
    RewriteRule ^default\.asp$ http://theitinerantgolfer.com/<font ...course</font>/ [NC,L,R=301]
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    [rant #4]
    The definition of an idiot is someone who repeatedly does the same thing expecting a different result. Asking Apache to confirm the existence of ANY module with an <IfModule> ... </IfModule> wrapper is the same thing in the webmaster world. DON'T BE AN IDIOT! If you don't know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache's resources (and should NEVER be allowed on a shared server).
    [/rant 4] # WordPress has an excuse: They don't want to bring down an idiot's website # if mod_rewrite is not available. You do NOT have any excuse to abuse a server # like this! RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
    RewriteCond %{HTTP_HOST} =theitinerantgolfer.com/Courses.aspx RewriteCond %{QUERY_STRING} =id=218 RewriteRule ^default\.asp$ http://theitinerantgolfer.com/<font ...course</font>/ [NC,L,R=301] # BEGIN WordPress <IfModule mod_rewrite.c> # Really??? Do I need to repeat my rant from above? RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
    # BEGIN WordPress <IfModule mod_rewrite.c> # Again??? RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress Redirect 301 /Courses.aspx?ID=218 http://theitinerantgolfer.com/pinehu...t-no-2-course/
    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

  3. #3
    SitePoint Member
    Join Date
    May 2007
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DK, thanks for replying to my post.

    I should have noted in my original post that I have no experience with this. I know HTML, CSS and can make educated guesses at altering Wordpress code (I am more of a designer than developer). The code examples above were from reading articles after searching "Redirect ASP to Wordpress", "Redirect ASP to PHP" or "Redirect Dynamic ASP to Wordpress".

    The ASP site was hosted at GoDaddy (windows server) but has switched to Wordpress at Hostgator (Linux Server).

    Courses.php does not exist.

    Are you saying that I should not be altering htaccess but httpd.conf or httpd-vhosts.conf?

    I do not see these files in the directory, would I just make them?

    Happy holidays to you.

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

    Thanks for not taking offense at my Standard Rant #4.

    The point of my response (and reference to RewriteMap) is that is the only way that mod_rewrite can help (without an inordinate number of 'capture the query string and redirect somewhere unrelated' directives). As a webmaster and not a sysadmin, you do NOT have access to the httpd.conf or your own httpd-vhosts.conf files (the httpd.conf is named differently - Apache2.conf - on a 'nix server) so you're stuck with abusing the server with a long series of directives OR using a handler script which could be activated by a !-f RewriteCond (albeit that would have to be carefully crafted to avoid crippling WP's !-f).

    On second thought, ditch ALL your .htaccess code and replace with this:
    Code:
    RewriteEngine on
    
    # handle Courses.aspx requests
    # ignore the query string as it'll be passed through unaffected
    RewriteRule ^Courses\.aspx$ handler.php [L,N]
    # The Last will prevent being ANDed with the WP code;
    # The Next will allow the handler to accept the request and perform the redirection
    
    # BEGIN WordPress
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? /index.php [L]
    # Making the . optional will account for the empty filename, i.e., DirectoryIndex request
    # END WordPress
    You will then have to create the handler.php script which MUST NOT output any content! It'll have to read your query string and determine the name of the redirection, i.e., pinehurst-resort-no-2-course - BUT DROP THE TRAILING / as that will upset WP! Then use PHP's header("Location: {insert redirection here}"); and handler will request the file from WP (via the .htaccess again).

    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

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    hg,
    Code:
    <?php // handler.php
    
    // initialize redirection map
    $map= array(218 => 'pinehurst-resort-no-2-course');
    // remainder of ID mappings
    
    # initialize return value
    $newURI = '';
    
    # get ID as integer
    if (isset($_GET['ID']))
    {
        $ID = $_GET['ID'];
        if (isset($map[$ID])) $newURI =  $map[$ID];
    }
    
    # redirection 
    header("Location:$newURI",TRUE,301); // OR header("Location:http://theitinerantgolfer.com/$newURI",TRUE,301);
    ?>
    This code is untested but it should work for you (if you choose to use a handler file as recommended).

    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


Tags for this Thread

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
  •