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.

.htaccess index.php removal PLUS 301 redirects

July 08, 2009 9:30am

Subscribe [4]
  • #1 / Jul 08, 2009 9:30am

    WDBookassist

    26 posts

    Hi,

    I’m using some fairly simple .htaccess to remove /index.php/ from my urls. This has worked fine for me until now.

    But I also now want to do some 301 redirects for old site urls that existed. I’m having trouble combining the two. Here’s my .htaccess file:

    RewriteEngine on
               
    # Everything else to the EE controller
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ /index.php?/$1 [L]               
    
    # A bunch of redirects                            
    Redirect 301 /rooms.php <a href="http://website.com/chambres/">http://website.com/chambres/</a>

    I’m going to need lots of redirects here, but I can’t get the first one working.

    When I try to visit http://website.com/rooms.php I am brought to
    http://website.com/chambres/?/rooms.php and don’t understand how it’s carrying the “rooms.php” across.

    (The 301 on its own works fine if I remove the index.php rewrite.)

    I had looked at other strategies for removing /index.php/ but I don’t think I can use them as I’m using a lot of pages and so have a lot of /page1/ /page2/ addresses, rather than /template/ as described in those approaches.

    Any ideas? My understanding of .htaccess is pretty basic.

  • #2 / Jul 08, 2009 1:15pm

    Manoj Thomas

    185 posts

    Hey Pierce, I haven’t checked to see if this works, but maybe try this out?

    RewriteEngine On
    rewriteRule ^rooms.php$ /chambres/ [R=301,L,NC]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

    (Generally I remove the index.php last in my .htaccess)

    Hope this helps,
    Manoj

  • #3 / Jul 08, 2009 1:24pm

    WDBookassist

    26 posts

    Hi Manoj,

    Hey, that worked nicely. Thanks!

    I had already tried reordering the 301 and the index.php rewrite, but it wasn’t working with my original code. Your rewrite seems to be functioning perfectly.

    Thanks, really appreciate it.
    Pierce

  • #4 / Jul 08, 2009 1:27pm

    Manoj Thomas

    185 posts

    sweet!

  • #5 / Jul 22, 2009 7:22pm

    giovanni

    209 posts

    I have been trying in various ways to achieve the removal of “index.php” from my URLS but i have never succeeded.

    is that we need to also update the Path Settings info in our Weblog Administration ›  Weblog Management ›  Edit Weblog Preferences section??

    At the moment I have http://www.example.com/index.php/contact  Should we updating that and remove the “index.php” part?

  • #6 / Jul 23, 2009 4:48pm

    Manoj Thomas

    185 posts

    Hi giovanni, good point - that .htaccess snippet should work in removing ‘index.php’ from your URLs, but you’ll also need to edit your General Configuration (CP Home ›  Admin ›  System Preferences ›  General Configuration) and leave the Name of your site’s index page field empty.

    Hope that helps!

    Manoj

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

ExpressionEngine News!

#eecms, #events, #releases