Forum Moderators: phranque

Message Too Old, No Replies

Redirecting index.php?cat=0 to index.php

Problems with htaccess

         

zapotex

9:11 pm on Nov 28, 2011 (gmt 0)

10+ Year Member



Hi everyone!

I'm disturbing you again with a problem related to .htaccess.

I'm using the instruction:

RewriteCond %{REQUEST_URI} /galleries/index\.php?cat=0$
RewriteRule ^(.*) http://www.kubizo.com/galleries/index.php [L,R=301]


Unfortunately, when I type in my browser:
http://www.kubizo.com/galleries/index.php?cat=0

the page opens as it is, it is not redirected to [kubizo.com...] as I would like.

Can you help me find out what I'm doing wrong? I tried also escaping the question mark, but it does not work either. I also tried replacing the question mark with ^, but again it does not work.

Thanks a lot everyone!

g1smd

9:26 pm on Nov 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In fact you're lucky it didn't redirect. If it had redirected, the query string would be re-appended and that new request would match the rule again and would be redirected again in an infinite loop.

Request_URI contains only the path, not the query string. Your pattern cannot match.

Query_String holds the query string data. That's the one to check.

A deeper problem is that you should NOT redirect to index.php here. The canonical URL for a folder or for the index page in a folder ends with a trailing slash and should not include the index file name.

Use example.com in this forum. It stops the URL auto-linking process.

lucy24

11:27 pm on Nov 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You don't need REQUEST_URI at all unless you're rewriting to an entirely different page and need to distinguish between the rewrite and the original request. You only need QUERY_STRING. Forums Search will turn up several hundred threads from the last couple of months.

zapotex

11:43 am on Nov 30, 2011 (gmt 0)

10+ Year Member



Thank you so much guys!

This is the help I need - very basic things. I had no idea QUERY_STRING even existed :-)

Thanks a lot again! I'll try that!

g1smd

7:55 pm on Nov 30, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It's a difficult read, but you should read the Apache mod_rewrite manual at least several times. After reading through a few times some of it will start to make sense. :)

zapotex

8:21 pm on Nov 30, 2011 (gmt 0)

10+ Year Member



Thanks for the suggestion! I will force myself to do that! :-)