0
votes

I've recently launched a codeigniter website and need to make some 301 redirects from the old site to the new one. They won't work with regex, so, as there are only a few, I can write redirects for each page. However, after hours of Googling/correcting, I still have no joy. The old site's URLs are .html files, wheras my codeigniter URLs are "clean" URLs. Here's my current .htaccess file:

<IfModule mod_alias.c>
   redirect 301 "/index.html" /index.php
</IfModule>

<IfModule mod_rewrite.c>
    DirectoryIndex index.php
    RewriteEngine on

    #This is the redirect I've been trying to make work
    RewriteRule ^/about-us.html /index.php?/about-us [R=301,L]

    RewriteCond $1 !^(index\.php|index\.html|lib|robots\.txt)
    RewriteRule ^(.*)$ index.php?/$1 

</IfModule>

Any ideas?

1

1 Answers

1
votes

You can use:

RewriteRule ^(about-us)\.html$ /index.php?/$1 [R=301,NC,L,QSA]

Or for redirecting all old .html links:

RewriteRule ^(.+?)\.html$ /index.php?/$1 [R=301,NC,L,QSA]

EDIT: Based on comments, you just need this rule to take care of old URLs:

RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]