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.

301 Redirect Help

June 19, 2009 6:48am

Subscribe [1]
  • #1 / Jun 19, 2009 6:48am

    medic119

    52 posts

    I have been saving my old templates to preserve the static links for my site.  Ie (mydomain.com/index.php/oldtempl/article will still load the article against the old template)

    I have recently discovered this is a bad thing to do.  It creates a lot of duplicate content (the entire site) in search engines and such.  So I went into my horribly confusing .htaccess to attempt to automatically redirect anything with templates X and Y to template Z thus redirecting any old templates into the new template automatically and allowing me to dump the old template files from EE and clean things up a bit.

    Problem is I am not very learned on regular expressions and haven’t been able to get it to work.

    Can someone help me out?  I am including the requisite potion of my .htaccess.

    *Also on a side note I used LG.htaccess to generate an htaccess file to remove .index.php.  Now system auto redirecting URLs (ie “view rendered template”) no longer work.  They just stop processing and dump the URL into the address bar (ie http://www.ffpblog.com/?URL=http://www.ffpblog.com/system/404/)  Any way to fix that? 

    Thanks a lot.

    AddHandler application/x-httpd-php5 .php
    
    RewriteEngine on
    
    Options +FollowSymlinks
    
    RewriteCond %{HTTP_HOST} ^old.ffpblog.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.old.ffpblog.com$
    RewriteRule ^(.*)$ "http\:\/\/www\.ffpblog\.com\/index\.php\/old" [R=301,L]
    
    *****EE SPAM BLOCK STUFF ****
    
    # -- LG .htaccess Generator Start --
    
    # .htaccess generated by LG .htaccess Generator v1.0.0
    # <a href="http://leevigraham.com/cms-customisation/expressionengine/addon/lg-htaccess-generator/">http://leevigraham.com/cms-customisation/expressionengine/addon/lg-htaccess-generator/</a>
    
    # secure .htaccess file
    <Files .htaccess>
     order allow,deny
     deny from all
    </Files>
    
    # Dont list files in index pages
    IndexIgnore *
    
    # EE 404 page for missing pages
    ErrorDocument 400 <a href="http://www.ffpblog.com/index.php?/system/400">http://www.ffpblog.com/index.php?/system/400</a>
    ErrorDocument 401 <a href="http://www.ffpblog.com/index.php?/system/401">http://www.ffpblog.com/index.php?/system/401</a>
    ErrorDocument 403 <a href="http://www.ffpblog.com/index.php?/system/403">http://www.ffpblog.com/index.php?/system/403</a>
    ErrorDocument 404 <a href="http://www.ffpblog.com/index.php?/system/404">http://www.ffpblog.com/index.php?/system/404</a>
    
    
    # Simple 404 for missing files
    <FilesMatch "(\.jpe?g|gif|png|bmp)$">
      ErrorDocument 404 "File Not Found"
    </FilesMatch>
    
    RewriteEngine On
    
    RewriteBase /
    
    # remove the www
    RewriteCond %{HTTP_HOST} ^(www\.$) [NC]
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # Add a trailing slash to paths without an extension
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule ^(.*)$ $1/ [L,R=301]
    
    # Remove index.php
    # Uses the "include method"
    # <a href="http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method">http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method</a>
    #Fixes CSS //////////
    RewriteCond %{QUERY_STRING} ^(css=.*)$ [NC]
    RewriteRule ^(.*)$ /index.php?/%1 [L]
    # remainder of removing inxex.php //////////
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} ^/(system|search|ffp|s|scrapbook|desert|ffp_public|mobile|Export|old||members|P[0-9]{2,8}) [NC]
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    # Remove IE image toolbar
    <FilesMatch "\.(html|htm|php)$">
      Header set imagetoolbar "no"
    </FilesMatch>
    
    
    
    # -- LG .htaccess Generator End --
  • #2 / Jun 19, 2009 11:37am

    medic119

    52 posts

    Ok, I spent some time dgging and this is what I came up with for the 301s I needed:

    #301 for old templates
    RewriteRule  ffp\/(.*)$    <a href="http://www.ffpblog.com/scrapbook/$1">http://www.ffpblog.com/scrapbook/$1</a> [L,R=301]
    RewriteRule desert\/(.*)$    <a href="http://www.ffpblog.com/scrapbook/$1">http://www.ffpblog.com/scrapbook/$1</a> [L,R=301]

    There has to be a better way to write this or combine this into already existing code listed above. 

    I Inserted this above the “Remove the www” code in the above file and it seems to work now regardless of www or not.  I want to make sure I am not adding too many redirects though for SEO optimizations as well.

    Also I am still having a problem with the URL redirects that the system kicks out.  I tried adding:

    RewriteCond %{QUERY_STRING} ^(URL=.*)$ [NC]
    RewriteRule ^(.*)$ /index.php?/%1 [L]

    to the .htaccess, bascially just swapping URL for css in the code as the actual URLs are formatted the same, but it will only generate an “invalid uri” when I try a redirect from inside EE (ie “View this template”)

    Thanks again for any help you can offer.

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

ExpressionEngine News!

#eecms, #events, #releases