0

I need to redirect

www.URL.it/directory_one/index.php?param_one=XXX&param_two=**YYY**

to

www.URL.it/newpage.php?param_three=**YYY**

I tried all I found online but the only things that works is redirect directory_one/index.php to newpage.php without parameters.

I tried this .htaccess

RewriteCond %{HTTP_HOST} =www.URL.it/directory_one/index.php? [NC]
RewriteCond %{QUERY_STRING} ^(param_one=XXX&param_two=**YYY**)
RewriteRule ^$ http://www.URL.it/newpage.php?%1 [R=301,L]

only to see if somethings happens but not works

I tried also

RewriteCond %{REQUEST_URI} /directory_one/index\.php
RewriteCond %{QUERY_STRING} param_one=XXX&param_two=**YYY**
RewriteRule ^(.*)$ http://www.URL.it/test/index.php? [L,R=301]

but nothings happened

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972

2 Answers2

0

Make sure you have AllowOverride set for the directory .htaccess resides in or Apache will ignore it.

Try this:

RewriteCond %{QUERY_STRING} param_one=XXX
RewriteCond %{QUERY_STRING} param_two=([^&]+)
RewriteRule ^/directory_one/index\.php$ http://www.URL.it/newpage.php?param_three=%1 [L,R]

If param_two really is to be YYY, use this as there is no need to use backreferences:

RewriteCond %{QUERY_STRING} param_one=XXX
RewriteCond %{QUERY_STRING} param_two=YYY
RewriteRule ^/directory_one/index\.php$ http://www.URL.it/newpage.php?param_three=YYY [L,R]

If none of the above work, another rule might take precedence or you may have placed the rules in the wrong spot. You should debug the whole thing with

RewriteLog /path/to/file.log
RewriteLogLevel 3
fuero
  • 9,591
  • 1
  • 35
  • 40
  • it doesn't work...;-( this is what I wrote: RewriteEngine On RewriteCond %{QUERY_STRING} main_page=product_info RewriteCond %{QUERY_STRING} products_id=([^&]+) RewriteRule ^/shop/index\.php$ http://www.url.it/schedafilm.php?id_film=%1 [L,R] nothing happens..... sorry but I can not indent the code properly – Luciano Michelini Sep 10 '13 at 12:14
  • Try specifying the full url, `http://www.url.it/...`, in the RewriteRule line. I just tested this in Apache/2.2.22 (Ubuntu), it works like a charm. – fuero Sep 10 '13 at 12:23
  • I used the full url, the last line was: RewriteRule ^/shop/index\.php$ http://www.url.it/schedafilm.php?id_film=%1 [L,R] – Luciano Michelini Sep 10 '13 at 12:32
  • i put the http but not appears – Luciano Michelini Sep 10 '13 at 12:33
  • I'm using Apache/2.2.14 (Unix) – Luciano Michelini Sep 10 '13 at 12:38
  • I've updated my answer. – fuero Sep 10 '13 at 14:09
  • Nothing happened? sounds like you need to set the allow override directive in the apache config. – Daniel Widrick Sep 10 '13 at 14:19
  • I added the two lines that you've reported at the end of the file, I created a file called file.log and set the path from the root but also with http in front but does not write anything. I tried to change it to file.txt but does not write anyway. I'm doing something wrong? I read online that I should add the server parameter SymLinksIfOwnerMatch, can it be? – Luciano Michelini Sep 10 '13 at 14:37
-1
RewriteCond %{QUERY_STRING} param_one=XXX
RewriteCond %{QUERY_STRING} param_two=.*YYY.*
rewriteRule (.*) www.URL.it/newpage.php?param_three=%{QUERY_STRING} param_two
chicks
  • 3,793
  • 10
  • 27
  • 36
Munni
  • 1