Forum Moderators: phranque

Message Too Old, No Replies

301 redirect from one dynamic url to other

         

fsmobilez

11:54 am on Sep 21, 2008 (gmt 0)

10+ Year Member



i have dynamic urls script based site

i want to redirect theseurls with same string some examples are

www.example.com/sms/jokes.php?joke_id=30&cat_id=33&jtype=
www.example.com/sms/jokes.php?joke_id=30&cat_id=33&jtype=1
www.example.com/sms/jokes.php?joke_id=5577&cat_id=20&jtype=
www.example.com/sms/jokes.php?joke_id=5577&cat_id=20&jtype=1

to
www.example.com/sms/jokes.php?joke_id=30&cat_id=33
www.example.com/sms/jokes.php?joke_id=5577&cat_id=20

means in simple words i want to remove string "jtype" ANd "jtype=1"
from the end of url

and
for

www.example.com/sms/jokes_category.php?cat_id=66&jtype=
www.example.com/sms/jokes_category.php?cat_id=66&jtype=1
www.example.com/sms/jokes_category.php?cat_id=100&jtype=
www.example.com/sms/jokes_category.php?cat_id=100&jtype=1

to

www.example.com/sms/jokes_category.php?cat_id=66
www.example.com/sms/jokes_category.php?cat_id=100

Will u post the exact coding here so that i can add in .httacess and
get rid of these links

jdMorgan

2:21 pm on Sep 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please review our Apache Forum Charter [webmasterworld.com] for information on how to get the most from this forum, and links to resources which will be useful to you in this project. You may also wish to search this forum for "dynamic URL rewriterule" and similar phrases -- The subject has been covered in-depth.

Then post your code as a basis for discussion.

Thanks,
Jim

fsmobilez

11:39 am on Sep 22, 2008 (gmt 0)

10+ Year Member



Will u plz only post the coding for me which i can add in .httaccess and get this rid of this tension as google have crawled duplicated links of my site , i will be really thankfull if u help me

i tried alot but can find the exact coding for these urls

londonhogfan

4:21 pm on Sep 23, 2008 (gmt 0)

10+ Year Member



I am having a very similar problem, but have not figured it out.

I had to change directories from "coaching-results" to "coaching-records" but also had quite a few with extra text at the end of the url. I tried this, but it did not work.

RewriteRule ^/db/coaching-results/1/coach-1-name/(.*)$ [mydomain.com...] [L,R]

if someone knows where I'm going wrong I think it would help both of us.

g1smd

4:26 pm on Sep 23, 2008 (gmt 0)

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



See this thread from earlier today with a very similar question:

[webmasterworld.com...]

Note, also, that [R] returns a 302 redirect, when you maybe need a 301.

fsmobilez

6:03 pm on Sep 23, 2008 (gmt 0)

10+ Year Member



ok jdmorgan i have created this rewrite command after a hardwork but it is not working will u plz help me with it

example url

www.example.com/sms/jokes_category.php?cat_id=66&jtype=1


RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} .
RewriteRule ^(.*)\.php\?(cat\ id=.*)&$ /$1.php?$2 [R=301,L]

jdMorgan

12:53 am on Sep 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Query strings are not part of a URL, they are data attached to a URL to be passed to the resource at that URL. Therefore, RewriteRule cannot "see" them in the URL-path that it matches against your pattern. The query string must be handled in the RewriteCond, and parts of it can be back-referenced using %1 through %9.

Code in www.example.com/.htaccess :


RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^(joke_id=[^&]+&cat_id=[^&]+)&jtype=
RewriteRule ^sms/jokes\.php http://www.example.com/sms/jokes.php?%1 [R=301,L]
#
RewriteCond %{QUERY_STRING} ^(cat_id=[^&]+)&jtype=
RewriteRule ^sms/jokes_category\.php http://www.example.com/sms/jokes_category.php?%1 [R=301,L]

You can move this code into www.example.com/sms/.htaccess by removing both ocurrences of "sms/" from the patterns (only) of the two RewriteRules. Leave the "sms/" path-parts in the substitution URLs.

Jim

fsmobilez

10:47 am on Sep 24, 2008 (gmt 0)

10+ Year Member



Thanks thanks thanks thanks

This forum simply rocks

U r great, no words to express my feelings.

MY best regards always with u.