Forum Moderators: phranque

Message Too Old, No Replies

Redirect Dynamic URLs to Root

How to Redirect Dynamic URLs to Root

         

Severin

10:06 am on Apr 1, 2010 (gmt 0)

10+ Year Member



Hi everyone!
i m trying to redirect some urls that they aren using anymore but they have been indexed from google so i want to redirect to the homepage..

My old url seems like
"www.domain.com/video?videodirek=4125"

and i want to redirect all of the urls which contains "video?videodirek=#*$!x" but not contains only "video" variable because my video root is "www.domain.com/video"

i tried this code but its not work proparly.
"RewriteRule ^video?([^/-]*)$ [domain.com...] [L,R=301]

its only delete "video" word from url and i cant enter my video directory "www.domain.com/video"

Sorry for my english. i also read many docs for redirecting with htacess but i couldnt make a working code.

g1smd

10:38 am on Apr 1, 2010 (gmt 0)

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



RewriteRule cannot 'see' the query string part.

You need a preceding RewriteCond to examine the QUERY_STRING.

There was a thread on a similar topic only last week with much example code.

Severin

4:08 pm on Apr 1, 2010 (gmt 0)

10+ Year Member



i tried many combination but they did not work.

i tried them

RewriteRule ^video?task(.*)$ [domain.com$1...] [R=301,L]

RewriteCond %{query_string} ^video?
RewriteRule /* www.domain.com [R,L]

RewriteCond %{query_string} ^video?(.*)
RewriteRule (.*) [domain.com...] [R=301,L]


RewriteCond %{query_string} ^video([?]*)
RewriteRule (.*) [domain.com...] [R=301,L]

they gives me still "video?videodirek=4125"

g1smd

4:54 pm on Apr 1, 2010 (gmt 0)

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



Clear the query string with a question mark after the target URL.

Query_String looks only at the stuff after the question mark.

Your third attempt is the closest.

The pattern
video?(.*)
will make the "o" optional, and then place
direk=4125
into the backreference.

Adjust the pattern so that all after = goes into the backreference.

Severin

5:28 pm on Apr 1, 2010 (gmt 0)

10+ Year Member



if i use this code

RewriteRule ^video?([^/]*)$ http://www.example.com/ [L,R=301]

my link seems like this
www.domain.com/?videodirek=4125

its only remove "video"

and
if i use this

RewriteCond %{query_string} ^video?(.*)
RewriteRule ^video?([^/]*)$ http://www.example.com/

its nothing do


i read many docs about it but i m so confused..
i can't figure it out

[edited by: jdMorgan at 6:53 pm (utc) on Apr 1, 2010]
[edit reason] example.com [/edit]

g1smd

6:11 pm on Apr 1, 2010 (gmt 0)

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



RewriteRule itself cannot 'see' anything after the question mark.

The RewriteCond looking at Query_String will see only the stuff after the question mark.

The pattern video?(.*) will make the "o" optional, and then place direk=4125 into the backreference. You're not matching enough characters before capturing the rest.

Adjust the pattern so that all after the equals sign goes into the backreference.

Clear the query string with a question mark after the target URL.

Severin

6:47 pm on Apr 1, 2010 (gmt 0)

10+ Year Member



g1smd could you write the true code please? you explain well but isnt there any way to solve this.

jdMorgan

7:00 pm on Apr 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have not followed all the previously-posted directions. You should have something like this:

RewriteCond %{QUERY_STRING} ^videodirek=[0-9]+
RewriteRule ^video$ http://www.example.com/video? [R=301,L]

Please do not proceed with coding until you have studied and understand the regular-expressions tutorial and the mod_rewrite documentation cited in our Forum Charter [webmasterworld.com]. Failure to do so can be quite dangerous to the ranking of your pages in search engines. This is server configuration code.

Jim

Severin

8:31 pm on Apr 1, 2010 (gmt 0)

10+ Year Member



Thank you so much. This code work like a charm..

g1smd

11:27 pm on Apr 1, 2010 (gmt 0)

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



But now you need to understand how it works, so you can maintain it should something change on your site that needs some more changes to be made to that code.