0

I want to do 301 redirection after removing index.php in codeigniter.

htaccess file:

RewriteEngine on

RewriteCond $1 !^(index\.php|images|css|img|js|plugins|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

After this I added

RewriteRule /index.php?page=9-someting&txt=12 /page/1/someting#2/other [R=301,L]

but redirection does not work any help?

EDIT:

/index.php?page=9-someting&txt=12 the old site that was not written in CodeIgniter

0

2 Answers 2

2

Move your second, more special rule before the usual CI's nice url's catch-all-and-send-to-index rule. You might also want to add NE (as no encode) because the hashmark (#) will be encoded otherwise.

So something like this:

RewriteEngine on
# rewrite old site url, has L so processig will stop here for matching requests.
RewriteCond %{QUERY_STRING} ^page=9-someting&txt=12$
RewriteRule index.php /page/1/someting#2/other [R=301,L,NE]


# request that fall trouhg will be sent to CI's front controller (if they are not images, css....)
RewriteCond $1 !^(index\.php|images|css|img|js|plugins|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
6
  • does not work, if I put anything except index.php everything is work normally.
    – Laky
    Commented Jun 25, 2013 at 8:21
  • Sorry, i just realized that you are trying to match query string parameters in the RewriteRule line. That's not gonna work there, you will have to use a RewriteCond since RewriteRules matches request's url-path.
    – complex857
    Commented Jun 25, 2013 at 8:38
  • This works, but is it possible that after the url redirection is not: mysite.com/page/1/someting#2/other?index.php?page=9-someting&txt=12
    – Laky
    Commented Jun 25, 2013 at 8:54
  • That should not happen, these rewrites are not supposed to be relative on the current URL, I'm not sure what's happening there.
    – complex857
    Commented Jun 25, 2013 at 8:59
  • Chrome says 'This webpage has a redirect loop'?
    – Laky
    Commented Jun 25, 2013 at 9:13
0

Try this one in .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L,R=301]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,R=301]
</IfModule>

RewriteRule ^index.php?page=9-someting&txt=12$ /page/1/someting#2/other [R=301,L]
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.