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.

Is EE causing this - 301 .htaccess

July 26, 2011 10:49am

Subscribe [2]
  • #1 / Jul 26, 2011 10:49am

    e-finity

    22 posts

    Hi all,

    Quick question -

    I am trying to do a simple 301 redirect using an .htaccess file.

    redirect 301 /old-page.php <a href="http://www.domain.com/new-page">http://www.domain.com/new-page</a>

    It works fine, except the URL looks like this -

    http://www.domain.com/new-page?old-page.php

    I don’t know why that variable is there and I can’t find anything explaining it so thought it may be EE related?

    It’s important the page isn’t indexed by search engines with that variable as it’ll create a duplicate content issue.

    Thanks!

  • #2 / Jul 26, 2011 11:47am

    Try this; make sure it’s above your EE rewrite rules.

    RewriteRule ^old-page.php$ <a href="http://www.domain.com/new-page">http://www.domain.com/new-page</a> [R=301,L]
  • #3 / Jul 26, 2011 11:51am

    e-finity

    22 posts

    It works fine in regards the redirect but I still get the variable at the end.

    I’ve 301’d pages before but I just don’t get this.

    Also, as said above I don’t know that this is an EE issue, just can’t find anything on it elsewhere so assume it maybe.

  • #4 / Jul 26, 2011 12:48pm

    Can you please post the contents of your .htaccess file?  It’s coming from a rewrite rule somewhere in there…

  • #5 / Jul 26, 2011 1:18pm

    e-finity

    22 posts

    Here you go -

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^domain.com
    RewriteRule (.*) <a href="http://www.domain.com/$1">http://www.domain.com/$1</a> [R=301,L]
    RewriteCond %{REQUEST_URI} ^/.*index.html$ 
    RewriteRule ^(.*)index.html$ $1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteRule ^(.*)$ /index.php?$1 [L

    Thanks.

  • #6 / Jul 26, 2011 2:44pm

    The redirect you mentioned doesn’t seem to appear in what you pasted there… can’t troubleshoot it unless it’s there.

  • #7 / Jul 26, 2011 4:55pm

    e-finity

    22 posts

    Sorry, literally looks like this - only with my domain.

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^domain.com
    RewriteRule (.*) <a href="http://www.domain.com/$1">http://www.domain.com/$1</a> [R=301,L]
    RewriteCond %{REQUEST_URI} ^/.*index.html$ 
    RewriteRule ^(.*)index.html$ $1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteRule ^(.*)$ /index.php?$1 [L
    
    redirect 301 /old-page.php <a href="http://www.domain.com/new-page">http://www.domain.com/new-page</a>

    Thanks.

  • #8 / Jul 26, 2011 5:25pm

    Per my original reply, your redirect needs to appear before/above your EE rewrite rules.  The order in which rules are written makes a difference.

    # Turn on the Rewrite Engine
    RewriteEngine On
    RewriteBase /
    
    # If no sub domain specified, bounce to www
    RewriteCond %{HTTP_HOST} ^domain.com
    RewriteRule (.*) <a href="http://www.domain.com/$1">http://www.domain.com/$1</a> [R=301,L]
    
    # If pulling up old-page.php, redirect to /new-page
    RewriteRule ^old-page.php$ <a href="http://www.domain.com/new-page">http://www.domain.com/new-page</a> [R=301,L] 
    
    # If accessing any index.html file, redirect to the location without index.html
    RewriteCond %{REQUEST_URI} ^/.*index.html$ 
    RewriteRule ^(.*)index.html$ $1 [R=301,L]
    
    # Standard EE index.php elimination; process any request that isn't a file, directory or graphic with index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteRule ^(.*)$ /index.php?$1 [L]
  • #9 / Jul 26, 2011 6:37pm

    e-finity

    22 posts

    Thanks for that -

    You know what, just by fluke that I had it open I tested this in Firefox, no variable on the URL, so tested it in Chrome, no variable - tested it in IE9 still has the variable in the URL.

    It must be browser related?

    I’ve cleared the cache out etc…

    My original concern was that Google would index the URL with the variable but I’m pretty sure it won’t now as it seems to be browser related.

    Thanks for cleaning up my .htaccess file!

  • #10 / Jul 26, 2011 6:41pm

    Dan Decker

    7338 posts

    Hello e-finity,

    Looks like this is no longer an issue for you? I’m going to move this into Community Help to keep this discussion going!

    Best,

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

ExpressionEngine News!

#eecms, #events, #releases