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.

few redirect questions

January 24, 2012 1:36pm

Subscribe [2]
  • #1 / Jan 24, 2012 1:36pm

    Matt76

    75 posts

    I am in the process of trying to get all the channels, links and everything redirected to help with rankings and such.  I have used all the info I have found here with searches and created my .htaccess file and just not sure if things are working the way they are supposed to.

    First off, here is my .htaccess file.  I may be trying to do to much, not sure
    http://www.heartlandoutdoors.com

    <IfModule mod_rewrite.c>
            RewriteEngine On
    
     RewriteCond %{HTTP_HOST} ^heartlandoutdoors\.com$ [NC]
     RewriteRule ^(.*)$ <a href="http://www.heartlandoutdoors.com/$1">http://www.heartlandoutdoors.com/$1</a> [R=301,L]
    
     Redirect /heartlandoutdoors.com/index.html <a href="http://www.heartlandoutdoors.com">http://www.heartlandoutdoors.com</a>
    
            # Removes index.php
            RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ /index.php/$1 [L]
    
            # If 404s, "No Input File" or every URL returns the same thing
            # make it /index.php?/$1 above (add the question mark)
    </IfModule>

    My goal is to make sure everything has a www and the index.php is removed from everything.  So far, the www redirect is working.  But everything still has index.php in the url.  I noticed all my nav_links have index.php/template and all my templates have index.php in them.  Do I need to go thru and change all those?  I did remove the index.php from the General Config.

    Anyway, I hope this enough info for everyone.  I am not very profitiant in this.

  • #2 / Jan 26, 2012 7:58am

    John St-Amand

    865 posts

    Here’s what I use to remove index.php and www:

    <IfModule mod_rewrite.c>
    
    # Enable Rewrite Engine
    # ------------------------------
    RewriteEngine On
    RewriteBase /
    
    # Redirect www Requests
    # ------------------------------
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    
    # Redirect index.php Requests
    # ------------------------------
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{THE_REQUEST} !/YOUR_SYSTEM_FOLDER_NAME_HERE/.*
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
    
    # Standard ExpressionEngine Rewrite
    # ------------------------------
    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    </IfModule>

    It’s worked for me pretty well so far.  Note that you need to insert your own system folder name in the index.php redirect.

    Hope you find it useful.

  • #3 / Jan 26, 2012 8:14am

    Matt76

    75 posts

    Thanks,
    When you say to insert my system folder name, are you talking about the standard url or the actual system directory?

  • #4 / Jan 26, 2012 8:17am

    John St-Amand

    865 posts

    Just the folder name itself where I put “YOUR_SYSTEM_FOLDER_NAME_HERE”.  It could be “system” or whatever you may have renamed it.

  • #5 / Jan 26, 2012 8:23am

    Matt76

    75 posts

    ok.  So the actual folder that holds EE site? 

    Sorry, not enough coffee yet this morning.

  • #6 / Jan 26, 2012 8:25am

    John St-Amand

    865 posts

    No, that’s the folder that you use to access your control panel - assuming you’re not accessing it via admin.php.  I usually delete admin.php (or rename it) and continue to access the CP through my renamed system directory.  It’s the name of that directory that i include in the htaccess file to ensure that it remains accessible.

  • #7 / Jan 26, 2012 8:42am

    Matt76

    75 posts

    Got It.  It works great.  Does everything perfect.

    Now I need to decide if I want WWW or not.  I know it taking off the WWW right now, what would that code be if I wanted to have WWW on everything?

    Thanks
    Matt

  • #8 / Jan 26, 2012 8:44am

    John St-Amand

    865 posts

    You would just remove these lines:

    # Redirect www Requests
    # ------------------------------
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    I like removing www to eliminate the possibility that Google might index www and non-www versions of the same URL.  Your could use htaccess to force www to be present, or, as above, you can remove it.

  • #9 / Jan 26, 2012 8:48am

    Matt76

    75 posts

    Thank you very much.  This has been a huge help.

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

ExpressionEngine News!

#eecms, #events, #releases