2

I am using codeigniter for my website, and before theres always that index.php? on my every url or links, for example

mysite.com/index.php?/about

Google has indexed all of my urls with that index.php? and I want to remove it and redirect it without that. I am having a problem rewriting the URL and redirect it to mysite.com/about and this what i have tried so far

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?(/[^\s\?]+)? [NC]
RewriteRule ^ %1/ [QSA,L,R=301]

what happened is, it only removed the index.php, for example mysite.com/index.php?/about will turn to mysite.com/?/about I don't know how to remove that question mark,

I'm not good on mod_rewrite thanks in advance for the help.

1
  • 1
    That question mark (?) after `+index\.php` will prevent your rule on removing the index.php, especially if tried mysite.com/index.php
    – Ramje
    Commented Jun 13, 2013 at 6:35

2 Answers 2

2

I think you can improve the rules slightly.

RewriteCond %{REQUEST_URI}?%{QUERY_STRING} index\.php?\?.+
RewriteRule .*$ %{QUERY_STRING}? [R=301,L]

Essentially, you don't have to worry about the entire request line in %{THE_REQUEST}, which removes all the complicated regex. Also, the rule redirects to whatever is listed in %{QUERY_STRING}, and removes the query string.

I am not sure why you used QSA in the first place. I think that was part of the problem earlier. Just for an exercise, you can try removing QSA and see what happens.

0
1

You should try this one.

RewriteCond %{QUERY_STRING} ^/[a-z]+$ [NC]
RewriteRule ^/index.php$ %{QUERY_STRING} [NC,L,R=301]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.