Answer the question
In order to leave comments, you need to log in
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
Answer the question
In order to leave comments, you need to log in
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]
RewriteCond %{QUERY_STRING} ^/product/oki_([0-9])$
RewriteRule ^index /product/oki_%1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question