Forum Moderators: phranque

Message Too Old, No Replies

simple rewrite rule not working

rewrite rule doesnt redirect

         

phparion

6:11 am on May 31, 2007 (gmt 0)

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



Hi

RewriteRule ^articles.php?(.+)&aid=(.+) articles/$2/$1.php [nc,l]

this rewrite rule does no redirect

my goal is to redirect dynamic url to a static url e.g

articles.php?string&aid=digit

articles/digit/string.php

I wonder if someone could help in this.

thanks

g1smd

10:34 am on May 31, 2007 (gmt 0)

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



I originally assumed that the problem is in the use of (.+), nothing is being matched and stored.

You also need a \ in this bit: articles\.php.

.

However, looking deeper, there is more:

You say it does not redirect. It won't redirect, there is no [R] in the code. You have an internal rewrite.

If someone asks for articles.php/sometopic&aid=12345 the server silently tries to pull content from the /username/html_public/yoursite/article/12345/sometopic/ folder on your server.

Add the [R=301] to this code to make this into a redirect.

You'll also need a rewrite in the opposite direction to stop any duplicate content issues.

That is, you need one internal rewrite and one [R=301] redirect. Anything else will cause an infinite loop.

.

All this assumes that the links on your page will be in the "folder structure"-like format.

phparion

4:47 pm on May 31, 2007 (gmt 0)

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



thanks for your reply.

so what should I use instead of (.+)?

I do have a reverse rewrite rule to avoid duplicate contents.

I have tried \.php too but no effect. I have also used R=306 but in vain.

I also dug out Jim's reply to another fello where about cig-bin based redirect and tried to use his code matching with my htaccess but of no use.

g1smd

5:08 pm on May 31, 2007 (gmt 0)

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



>> I do have a reverse rewrite rule to avoid duplicate contents. <<

One of them needs to be a rewrite and the other a redirect.

Is that what you have? One has [R=301] and the other does not?

g1smd

5:09 pm on May 31, 2007 (gmt 0)

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



Which URL do you have in your clickable links on the pages of the site?

jdMorgan

12:18 am on Jun 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Tutorial: [webmasterworld.com...]

Jim

phparion

7:20 am on Jun 1, 2007 (gmt 0)

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



RewriteRule ^article/(.+)/(.+).php articles.php?aid=$1 [nc,l]

this is the other rule. the clickable URLs are of the above rules shape as normally done for SE friendly URLs

the problem is that SEs have listed my dynamic URLs too from the times when I didn't have mod rewrite implemented on the site. So to avoid duplicate contents penalty I am trying to rewrite the dynamic URLs on the fly to a Static URL as permanent removed URL.

the above rule works well without any problem however its reverse rule is not working.

jdMorgan

1:14 pm on Jun 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Both issues --the internal rewrite of static to dynamic, and the external redirect of dynamic to static to fix search listings-- are covered in the cited thread. If you're still having a problem, then please post the problematic code with the domain name examplified.

Jim

g1smd

6:48 pm on Jun 1, 2007 (gmt 0)

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



The main problem is that you have two internal rewrites.

Both URLs return content and a "200 OK" status I assume.

That is wrong.

You really want one of them to be a [R=301] redirect.