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.

How to remove index.php from urls with a 301 redirect

September 26, 2012 5:30pm

Subscribe [2]
  • #1 / Sep 26, 2012 5:30pm

    martinj

    32 posts

    Hi all

    The official method for removing index.php from urls (here) is working great for me except for one small problem: the home page is still accessible with index.php included in the URL. I.e.: http://www.vossbrook.co.uk/ shows the same content as http://www.vossbrook.co.uk/index.php

    Without getting into a discussion on SEO and duplicate content, I’m looking for a way using .htaccess of 301 redirecting the url containing index.php to it’s equivalent without index.php. I.e. http://www.vossbrook.co.uk/index.php 301 redirects to http://www.vossbrook.co.uk/. I’m not an expert in .htaccess and everything I’ve tried so far has simply broken the existing URL rewrites.

    If anyone has a solution to what I’m trying to do I’d really appreciate hearing about it.

    Thanks!

    Martin

  • #2 / Sep 27, 2012 4:00pm

    Kevin Smith

    4784 posts

    Hi Martin,

    I’m afraid we can only provide a limited scope of support when it comes to .htaccess rules, but I’d be more than happy to move this thread over to the Development and Programming or Community Help forum so that other developers can provide some help. Would you like me to do that?

  • #3 / Oct 01, 2012 12:04pm

    martinj

    32 posts

    Hi Kevin

    Thanks for the reply, yes please do move it over. Sounds like it should have been posted in a different Forum from the beginning as it was really aimed at the wider EE community rather than specifically for you guys.

  • #4 / Oct 01, 2012 12:46pm

    Kevin Smith

    4784 posts

    Sure thing, Martin!

  • #5 / Oct 06, 2012 4:59am

    lehrerfreund

    263 posts

    Hi martinj,
    I think the solution is here: http://kevinthompson.info/blog/completely-remove-index-php-from-expressionengine-urls/

    The code is:

    <IfModule mod_rewrite.c>
    
    # Enable Rewrite Engine
    # ------------------------------
    RewriteEngine On
    RewriteBase /
    
    # Redirect index.php Requests
    # ------------------------------
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{THE_REQUEST} !/system/.*
    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>

    For me this worked.
    Good luck.

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

ExpressionEngine News!

#eecms, #events, #releases