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.

htaccess redirect problems

February 10, 2012 2:37pm

Subscribe [2]
  • #1 / Feb 10, 2012 2:37pm

    pledbrook

    13 posts

    I have an old EE 1.6 site that has been migrated over to Wordpress (Sorry!) and I need to 301 redirect all the old articles to the new WP ones.

    My htaccess is working file on simple html redirects but when i try to redirect an EE url nothing happens. On a simple redirect like this…

    redirect 301 /index.php?/old_category/old_page_link /new/new-page-link

    nothing works. I’ve tried every style of redirect syntax I know and nothing seems to do anything.

    Is there anything in the way EE deals with url requests that would mean the htaccess redirect is getting missed or ignored? I thought htaccess rules ran first but maybe theres something in EE I’m missing or a trick to doing it.

    Any hep would be massively appreciated as I’ve spent hours with my hosting company tracking the issues down to this level.

    Thanks
    Paul

  • #2 / Feb 11, 2012 10:34pm

    Dan Decker

    7338 posts

    Hi Paul,

    .htaccess “runs” before ExpressionEngine comes into the picture. The directives are executed by the web server before any pages are served. This is one way that .htaccess can rewrite the URL before it served to browser.

    Hove you tried:

    redirect 301 /index.php?/old_category/old_page_link <a href="http://domain.tld/new/new-page-link">http://domain.tld/new/new-page-link</a>

    Cheers!

  • #3 / Feb 11, 2012 11:00pm

    Nevin Lyne

    370 posts

    Redirect in .htaccess ignores query strings, so anything after the ? is being ignored so it will never redirect as you think it will.  You will need to do actual mod_rewrite instead of simple Redirects a good starter article can be found here: http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/

  • #4 / Feb 13, 2012 4:47am

    pledbrook

    13 posts

    Yes, you’re correct, it does treat the ? as a query string so normal redirects won’t work. It took me a while to figure that one out but I did find a way to get it to work with htaccess code.

    The URL has to be split up and works out the old url based on everything that comes after the ?

    RewriteCond %{QUERY_STRING} ^/rest/ofURL/afterquestionmark/$ 
    RewriteRule ^index\.php$ <a href="http://example.com/new/URL">http://example.com/new/URL</a>? [L,R=301]

    Please not the ? on the end of the last line, this stops the query string from the first line getting appended to the new URL.

    Hope this helps anyone else with the same problem.

  • #5 / Feb 13, 2012 5:55pm

    Dan Decker

    7338 posts

    Hi pledbrook,

    I’m glad you were able to come to a solution! Thanks for sharing for the benefit of the community.

    Nevin, thank you for lending your expertise as well!

    pled brook, if you need assistance in the future, just let us know in a new thread.

    Cheers!

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

ExpressionEngine News!

#eecms, #events, #releases