Forum Moderators: phranque

Message Too Old, No Replies

Got 301 re-direct it to work using php

possible to do it in .htaccess?

         

soquinn

6:47 pm on Apr 19, 2005 (gmt 0)

10+ Year Member



We’re trying to re-write 2-3 rules for our deep directory content to be moved up. Changes were made to our script template so deep categories can be set as a home category but this creates duplicate content from the script so we wanted a request for:

http*//www.foo.com/main/index.php?a=foo1/foo2/foo3/foo4/…

to be a 301 to

http*//www.foo.com/main/foo4/…

We tried these 3 directives in .htaccess after reading through many threads but with no luck so far:

1)

redirect 301 /main/index.php?a=foo1/foo2/foo3/foo4 http*//www.foo.com/main/foo4/

2)

Options +FollowSymLinks
rewriteEngine on
RewriteCond %{QUERY_STRING} ^ a=foo1/foo2/foo3/foo4$
RewriteRule ^index\.php$ http*//www.foo.com/main/foo4/ [R=301,L]

3)

Options +FollowSymLinks
rewriteEngine on
rewriteBase /main/index.php?a=foo1/foo2/foo3/foo4
rewriteRule ^(.+) http*//www.foo.com/main/foo4$1 [L,R=301]

Any suggestions where we’re doing something wrong?

jd01

7:45 pm on Apr 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you are pretty close with your second idea... There are a couple of small adujstments I would suggest trying...

RewriteCond %{QUERY_STRING} ^foo1/foo2/foo3/foo4$
RewriteRule ^.*$ http*//www.foo.com/main/foo4/ [R=301,L]

You could also use {THE_REQUEST} which will examine the full original request for the url you are rewriting... it would look something like this:

RewriteCond %{THE_REQUEST} ^/index\.php\?a=foo1/foo2/foo3/foo4$
RewriteRule ^.*$ http*//www.foo.com/main/foo4/ [R=301,L]

Hope this helps.

Justin

soquinn

8:15 pm on Apr 19, 2005 (gmt 0)

10+ Year Member



Thanks Justin, funny they (and variations) didn't take either... might have to just go back to trying the 301 in our php template.

jd01

8:25 pm on Apr 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I missed this...

/main/index.php

try:

RewriteCond %{THE_REQUEST} ^/main/index\.php\?a=foo1/foo2/foo3/foo4$
RewriteRule ^.*$ http*//www.foo.com/main/foo4/ [R=301,L]

or make sure the .htaccess file is in the /main/ directory...

Justin