Homework-Heroes.com
Homework-Heroes.com

Reputation: 3

301 redirect with query strings

I'm new to programming and brand new to this site (although it has helped out many times as I'm trying to learn this stuff...so THANKS for all the help so far!).

My question relates to 301 redirects. I've been searching this site as well as many other pages through google and can't seem to find a solution that works for me (I'm guessing that the solution is probably already out there since it seems like a common problem...but I haven't yet been able to find it).

So here it is:

I have a site where: http://homework-heroes.com/php/views/newAssignment.php?[then any query string] always goes to the same page.

For the sake of eliminating duplicate content as seen by google, I want these to always redirect to: http://homework-heroes.com/php/views/newAssignment.php?final

What is the htaccess code I should insert to accomplish this?

Thanks in advance!

Upvotes: 0

Views: 93

Answers (1)

Mike Rockétt
Mike Rockétt

Reputation: 9007

Place the following in your /.htaccess file:

RewriteRngine On
RewriteRule %{QUERY_STRING} !^$
RewriteRule %{QUERY_STRING} !^final$
RewriteRule ^(php/views/newAssignment.php)$ /$1?final [R=302,NC,L]

The above basically says that if the query string is not blank and a request is being made to /php/views/newAssignment.php, then redirect to the same page with ?final as the new query string.

Alternatively, if you would like to remove the query string altogether, just remove final,leave the question mark in the rule, and remove the second condition.

If you're happy and want to make the redirect permanent, change 302 to 301.

Upvotes: 1

Related Questions