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.

Help needed with .htaccess RewriteRules

October 01, 2008 6:39pm

Subscribe [3]
  • #1 / Oct 01, 2008 6:39pm

    I have just launched a new EE site and want to have some of the old site addresses re-written to direct to the new ones. I am removing the index.php using the “include” method in the Wiki
    The old addresses were in the form:
    http://www.esoc.org.uk/?page=home
    This is my .htaccess code:

    RewriteEngine on
    
    RewriteRule ^\?page=home$ /home/ [L,R=301]
    RewriteRule ^\?page=events$ /home/events/ [L,R=301]
    RewriteRule ^\?page=permanent$ /home/poc/ [L,R=301]
    
    
    RewriteCond $1 ^(home|search|member|P[0-9]{2,8}) [NC]
    RewriteRule ^(.*)$ /index.php/$1 [L]

    This isn’t working, if I have the Global Template Preferences set to serve a 404, that’s what I get when I load the old address, not a re-written url.

    I think it’s got something to do with the leading ? in the old address, any ideas?

  • #2 / Oct 02, 2008 3:01am

    Robert Mirabito

    58 posts

    You really only need the L on the last rule in your .htaccess file.  The [L] means this is the last rule and to stop processing any further rules.

  • #3 / Oct 02, 2008 2:36pm

    I think I have found the solution, well it seems to be working anyway. If anyone can spot any errors let me know.

    RewriteEngine on
    
    RewriteCond %{QUERY_STRING} page=(home)
    RewriteRule ^/?$ <a href="http://www.esoc.org.uk/%1">http://www.esoc.org.uk/%1</a>? [R=301]
    
    RewriteCond %{QUERY_STRING} page=(events)
    RewriteRule ^/?$ <a href="http://www.esoc.org.uk/home/%1">http://www.esoc.org.uk/home/%1</a>? [R=301]
    
    RewriteCond %{QUERY_STRING} page=(permanent)
    RewriteRule ^/?$ <a href="http://www.esoc.org.uk/home/poc">http://www.esoc.org.uk/home/poc</a>? [R=301]
    
    
    RewriteCond $1 ^(home|search|member|P[0-9]{2,8}) [NC]
    RewriteRule ^(.*)$ /index.php/$1 [L]
  • #4 / Oct 03, 2008 2:51am

    Doggie52

    113 posts

    Not that I’m incredibly good at htaccess, but I sure never have seen anyone using it like that. Good job!

  • #5 / Oct 03, 2008 6:49am

    I had read somewhere that you should use the full url for 301 redirects, can anyone confirm if that’s the case?

    RewriteCond %{QUERY_STRING} page=(results)
    RewriteRule ^/?$ /home/%1? [R=301]

    The above works but I’m not sure if Google prefers:

    RewriteCond %{QUERY_STRING} page=(results)
    RewriteRule ^/?$ <a href="http://www.esoc.org.uk/home/%1">http://www.esoc.org.uk/home/%1</a>? [R=301]
  • #6 / Oct 08, 2008 12:49am

    Robert Mirabito

    58 posts

    The main thing to be aware of with redirects and rewriting URL’s is that Google only gets one URL for any page. For example… http://www.mysite.com and http://www.mysite.com/index.html are the same page but search engines may look at this as two separate pages and may potentially create a duplicate content issue.

    Fortunately search engines are getting smarter at dealing with these common issues like the example above but more uncommon examples may not be treated as kindly.

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

ExpressionEngine News!

#eecms, #events, #releases