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.

Remove index.php and Redirect 301 on Same .htaccess file?

February 17, 2011 8:01pm

Subscribe [2]
  • #1 / Feb 17, 2011 8:01pm

    Unifusion

    103 posts

    Hi there,

    So I built a site and removed index.php using this .htaccess code:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

    The client now wants to add 301 Redirects to the .htaccess file. What’s the best way to do that without breaking the site?

    Thanks!

    [Mod Edit: Moved to the CodeShare Corner]

  • #2 / Feb 23, 2011 1:08pm

    Unifusion

    103 posts

    So I’ve been playing around with this and I’ve had some success, but still problems:

    RewriteEngine On
    RewriteRule ^about/(.*)$ /dr_dee_tadlocks_reading_revolution/$1 [R=301,L]
    RewriteRule ^school/(.*)$ /k_12/$1 [R=301,L]
    RewriteRule ^native/(.*)$ /native_peoples/$1 [R=301,L]
    RewriteRule ^individual/(.*)$ /private_tutoring/$1 [R=301,L]
    RewriteRule ^workforce/(.*)$ /workforce_literacy/$1 [R=301,L]
    RewriteRule ^news/(.*)$ /in_the_news/$1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

    The first problem is that some of the redirects work, while others (school & workforce) go to the 404 page. My other problem is that I also need redirects for index.html and index.htm, but there seems to be an issue because of the index.php removal.

    Any ideas? Thank you!

  • #3 / Jun 22, 2011 4:58am

    CIB

    5 posts

    Any progress on this - I need to do something similar…

  • #4 / Jun 22, 2011 12:18pm

    Unifusion

    103 posts

    Hi @CIB,

    Here’s an abridged version of what I ended up with:

    RewriteEngine On
    RewriteRule ^index\.htm$ <a href="http://www.myurl.com/">http://www.myurl.com/</a>  [R=301,L]
    RewriteRule ^index\.html$ <a href="http://www.myurl.com/">http://www.myurl.com/</a>  [R=301,L]
    RewriteRule ^about(.*) /about/ [R=301,L]
    RewriteRule ^history(.*) /history/ [R=301,L]
    RewriteRule ^news(.*) /in_the_news/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

    I was having those problems because my genius of a client decided to upload folders to the root of the site with the same names as the pages I was trying to redirect from, resulting in a loop.

    You might also check out this thread, which I think uses a method that’s a lot easier to understand.

    Hope that helped, this .htaccess business can be a real pain.

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

ExpressionEngine News!

#eecms, #events, #releases