Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite help

duplicate urls

         

Dilly

12:34 am on Nov 18, 2007 (gmt 0)

10+ Year Member




I have a set of friendly urls that contain 2 variables.

e.g. make-var1-details-var2.php

now the info on the above url can also be obtained from

make.php?Id=var1

this has been indexed by google 2 pages with diff urls.

How do i get rid of the unfriendly url using mod_rewrite.

i think i need it to point to a 404 is that right?

Thanx

jdMorgan

2:10 am on Nov 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Externally 301-redirect the unfriendly URL to the friendly one.

More info here [webmasterworld.com].

Jim

Dilly

11:06 am on Nov 18, 2007 (gmt 0)

10+ Year Member



yeh but how do you redirect a single variable unfriendly url to a friendly url that requires 2 variables as shown above.

Thanx Jim

jdMorgan

2:57 pm on Nov 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As noted in the thread I referred you to, each form of the URL must contain all of the information required to infer the other.

You cannot 'create' information out of nothing, and as a result, what you seek to do is impossible unless the variable whose value is not present (in this case, "var2") can be given a fixed value.

Jim

Dilly

3:17 pm on Nov 18, 2007 (gmt 0)

10+ Year Member



Yes I understand where you are coming from Jim but the problem I have is that I have 3 urls that all lead to the same page as follows.

Link 1 - make.php?Id=var1&Model=var2 (Unfriendly Url)

Link 2 - make-var1-details-var2.php (mod rewrite friendly url of Link 1)

Link 3 - make.php?Id=var1 ( Unwanted Url that is being crawled)

Ok Link 1 and 2 are ok and Link 1 has been redirected 301 to Link 2 which is the new friendly Url. Now link 3 is an url that is unwanted and is some how being indexed which i dont want.

How do i just stop link 3 being crawled and let the first 2 links do there jobs.

Thanx

jdMorgan

3:23 pm on Nov 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use a RewriteCond to detect the query string, and if matched use a RewriteRule to redirect it, generate a 410-Gone, or rewrite it to a path that does not exist to generate a 404-Not Found.

Jim

Dilly

6:43 pm on Nov 18, 2007 (gmt 0)

10+ Year Member



Thanx a lot for the help and guidance Jim I tried this and it works.

RewriteCond %{query_STRING} &?Id=([^&]+) [NC]
RewriteRule ^Make\.php$ 404notfound.php? [NC,L]

Seems to work fine and show a 404 error as there is no such file called 404notfound.php. Is this the most efficient method in your eyes and thanx again for the help.

Dilly

6:50 pm on Nov 18, 2007 (gmt 0)

10+ Year Member



Ahhh! just realised that the friendly urls seem to 404 now aswell so the code doesnt work fully.

Dilly

7:28 pm on Nov 18, 2007 (gmt 0)

10+ Year Member



I think I need the condition to say that the when?Id=Var1 comes directly after Make.php then 404 page not found otherwise if it comes after other queries then dont 404.

e.g. If Make.php?Id=var1 then 404 page not found

but if Make.php?blag=var2&Id=var1 then dont 404 but carry on as per usual.

So if Id variable comes directly after filename Make.php i need it to 404 otherwise dont. Hope this is possible. Thanx

jdMorgan

8:04 pm on Nov 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anchor your query string pattern:

RewriteCond %{query_STRING} ^Id=[^&]+$ [NC]
RewriteRule ^Make\.php$ 404notfound.php? [NC,L]

Jim

[edited by: jdMorgan at 8:04 pm (utc) on Nov. 18, 2007]

Dilly

8:16 pm on Nov 18, 2007 (gmt 0)

10+ Year Member



Excellent works a treat thanks a lot jim u the best as per usual. lol