ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to 301 redirect old urls with query strings to new EE urls?

August 30, 2012 8:45am

Subscribe [3]
  • #1 / Aug 30, 2012 8:45am

    Jim Pannell

    187 posts

    Hi there

    We’re about to launch a new site for a client and need some help figuring out how to redirect their old, non EE urls to the new pages we’ve created in EE.

    I’d normally do a simple 301 redirect in the .htaccess file, but the problem here is that their old urls are in the following format:

    /contentpage.php?pageid=70

    The following results in a 404 on the new EE site:

    redirect 301 /contentpage.php?pageid=70 <a href="http://www.clientdomainname.com/their-new-page/">http://www.clientdomainname.com/their-new-page/</a>

    I’m fairly sure the answer is modrewrite, but can’t figure out how to go about writing the appropriate code. Anyone any ideas?

    My current .htaccess includes the following to hide index.php:

    # turn on RewriteEngine
    RewriteEngine on
    
    # Redirect non www to www
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ <a href="http://www.%{http_host}/$1">http://www.%{http_host}/$1</a> [R=301,L]
    
    # ee stuff
    RewriteCond $1 !^(assets|engine-room|robots\.txt|index\.php|admin\.php|webstat|googlea60d4a5d3d2f97fc\.html) [NC]
    RewriteRule ^(.*)$ /index.php/$1 [L]

    Looking forward to hearing if anyone has a solution.

    Cheers


    Jim

  • #2 / Aug 30, 2012 8:57am

    Rob Allen

    3105 posts

  • #3 / Aug 30, 2012 9:52am

    Jim Pannell

    187 posts

    Thanks Rob - interesting article but the examples there all follow a specific redirect pattern. The redirected urls in my situation don’t have any resemblance to the old urls.

    Edit:

    I figured it out. The following code redirects a url like /contentpage.php?pageid=70 to /schools/schools-we-work-with/:

    RewriteCond %{QUERY_STRING} pageid=70$ 
    RewriteRule (.*) /schools/schools-we-work-with/? [R=301,L]

    My situation required that I added multiple instances of this, but with different pageid=x parts and different redirect urls. Works a treat!

    Don’t forget to add a “?” at the end of your redirect url - that’s needed to not add the query string onto the end of the url.

     

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases