I
I
Ivan Polikarpov2015-03-23 13:35:30
Apache HTTP Server
Ivan Polikarpov, 2015-03-23 13:35:30

How to write a RewriteRule with a question mark in a string?

The bottom line is this:
There is a site on codeigniter. The index.php file has been removed from external urls, an internal redirect has been added to .htaccess:
RewriteRule ^(.*)$ /index.php?/$1 [L]
Google Webmaster found indexed links like this: Of
http://site.ru/index.php?/product/oki_c9655
course, these are duplicates of the same pages, but without "index.php?". Accordingly, it is necessary to set up a redirect in .htaccess from such pages to pages without "index.php?".
If only "index.php" was present in the url, then the problem would be solved by such a redirect:
RewriteRule ^index.php/(.*)$ /$1 [R=302,L]
and it works.
However, an attempt to set up such a redirect:
RewriteRule ^index.php?/(.*)$ /$1 [R=302,L]
does not lead to anything.
The problem, apparently, is that the question mark is considered as the beginning of the part of the url with parameters, which is not the case in this particular case. How to write a rule so that it works like this:

http://site.ru/index.php?/product/oki_c9655 –> http://site.ru/product/oki_c9655

?
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan Polikarpov, 2015-03-23
@taboo1387

I defeated the problem.
As a result, the part that is responsible for the transformation
looks like that:

RewriteCond %{QUERY_STRING} ^/(.*)$
RewriteRule ^index\.php$ /%1? [R=302,L]

The Request exceeded the limit of 10 internal redirects due to probable configuration error was due to the rule that followed.

I
IceJOKER, 2015-03-23
@IceJOKER

RewriteCond %{QUERY_STRING} ^/product/oki_([0-9])$ 
RewriteRule ^index /product/oki_%1

S
ShamblerR, 2015-03-23
@ShamblerR

RewriteCond %{REQUEST_URI} ^(.*)/index\.php$
  RewriteRule ^(.*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question