Htaccess remove parameter in query string

for some reason our CMS had added after every article ?language=en. We had it fixed but now I need to 301 redirect all links to /subcategory/%artical% without the ?language=en.

I want to redirect:

/subcategory/%artical%?language=en

to:

/subcategory/%artical%

I tried this RewriteRule:

RewriteRule ^subcategory/%1?language=en ^/subcategory/%1 [R=301,NC,L]

but it did not work.

5v,

WHAT?

Where did you create the %1 variable and why do you expect a RewriteRule to access the {%QUERY_STRING} variable?

Okay, this is also largely a repeat of another recent thread: Redirect search query string with edited search query.

I have offered a tutorial on mod_rewrite for many years and it’s helped many, MANY SitePoint members over those years. Have a look at http://dk.co.nz/seo if you want to learn something (in other words, don’t be a script kiddie; KNOW what any code you use is doing!).

RewriteEngine on RewriteCond %{QUERY_STRING} ^language=en$ RewriteRule .? %{REQUEST_URI}? [R=301,L]

I’ll leave it to you to learn what that does (i.e., WHY it removes the language=en if that is the entire query string OR how to change it simply to remove language=en if it’s embedded in a query string).

Regards,

DK

It’s true, working hard but allot to know, yea it’s worked.
The script was done to host multilanguage site but in the end it been run with only in 1 language and generating the links with the ?language=en in the sitemap.xml.
but in the html pages the links are without the language query and it’s case big content duplication issuse so we are fixing waiting to back to #1 in google :smile:
thank you dklynn
PS about the script kiddie it’s true i will read your tutorials cheers

5v,

'Glad it quickly resolved your issue. The ? with nothing after it in the redirection KILLS any query string and that’s not really a big secret.

IMHO, it’s critical that a webmaster know precisely what his/her code is doing before going online. My tutorial is overkill for what you needed (ergo the quick fix) but it should help you as there is a LOT of good information there (especially in the example explanations).

Regards,

DK

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.