LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need help with .htaccess (https://www.linuxquestions.org/questions/programming-9/need-help-with-htaccess-839604/)

guessity 10-21-2010 01:17 PM

Need help with .htaccess
 
For some reason google is indexing my site with the following for all the urls

Code:

?utm_source=twitterfeed&utm_medium=twitter
like

Code:

http://www.url.com/news/2010/10/people-live.html?utm_source=twitterfeed&utm_medium=twitter
Can anybody help me do a 301 redirect so my final url is

Code:

http://www.url.com/news/2010/10/people-live.html
It should basically remove the odd stuff and redirect for all the urls.

bathory 10-21-2010 01:33 PM

Hi,

Use the following in a .htaccess
Code:

RewriteEngine on

RewriteCond %{QUERY_STRING} ^utm_source=(.*)
RewriteRule (.*) http://www.url.com/news/2010/10/people_live.html? [R=301,L]

Regards

guessity 10-21-2010 01:36 PM

I have over 500 urls with the same problem.

Is it possible to remove them in one shot rather then create 500 ood lines?

bathory 10-21-2010 01:41 PM

Sure.
Just give more details, like what is the generic form of the URLs you want to rewrire and how they should look after rewritting

guessity 10-22-2010 12:59 AM

The problem is all my urls are being indexed by google with the following in the end -

Code:

?utm_source=twitterfeed&utm_medium=twitter
I basically want to 301 redirect to the original link without it at end.

bathory 10-22-2010 02:06 AM

So you want to remove the QUERY_STRING (everything after the 1st ?)
If that's the case, you can use:
Code:

RewriteEngine On

RewriteCond %{QUERY_STRING} !^$
RewriteRule (.*) /$1? [R=301,L]

Regards


All times are GMT -5. The time now is 11:46 PM.