homepage Welcome to WebmasterWorld Guest from 54.211.201.65
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
301 Redirect URL w Variables .htaccess
cjezowicz




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

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




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

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

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

The ^ and $ are not required.

jdMorgan




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

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




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

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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved