Welcome to WebmasterWorld Guest from 54.226.25.231

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 Redirect URL w Variables .htaccess

     

cjezowicz

5:25 pm on Jul 26, 2010 (gmt 0)

5+ Year Member



I've searched the forums and tried all the examples I could find but for some reason can't get this to work. I have a URL that needs to be 301 redirected because of duplicate content concerns.

http://www.example.edu/academics/degree-programs?q=degree-programs

...should read...

http://www.example.edu/academics/degree-programs

I have tried a number of solutions, here is the code I have currently. This did something similar on a different domain.

RewriteCond %{QUERY_STRING} ^q=degree-programs(.*)$
RewriteRule ^(.*)$ http://www.example.edu/academics/degree-programs$1? [R=301,L]

The thought behind this is that it should find anywhere the q=degree-programs query string appears and redirect it to the URL in rewrite rule. What's going wrong here?

[edited by: jdMorgan at 8:17 pm (utc) on Jul 26, 2010]
[edit reason] example.edu for readability [/edit]

g1smd

6:42 pm on Jul 26, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The ^ operator is "begins with" so it cannot match "anywhere".

Use
&?q=degree-programs&?
or similar.

The ^ and $ are not required.

jdMorgan

8:33 pm on Jul 26, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Also, the code and your example don't match. How much of the URL-path is variable, and how much of it is fixed?

It seems that you are adding a "second copy" of "/academics/degree-programs" into the URL-path with the code that you have posted, unless the code is located in /academics/degree-programs/.htaccess

Is that the case?

Jim

cjezowicz

1:16 pm on Jul 27, 2010 (gmt 0)

5+ Year Member



The .htaccess resides in the root directory. And I took what he said and turned it into...

RewriteCond %{QUERY_STRING} &?q=advanced-certificate-programs$
RewriteRule ^(.*)$ [domain.edu...] [R=301,L]

which works in every case I have currently. The way you mentioned it might be duplicating the page worries me. What did you mean by that?

Thanks guys, your always so much help!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month