.htaccess problem on apache

Discussion in 'Site & Server Administration' started by kinggomez, Apr 27, 2011.

  1. #1
    I have a URL that looks like this: mywebsite.com/mypage?lang=fr

    How can I remove the "?lang=fr" from the end with htaccess? I am not sure how to get it working.
     
    kinggomez, Apr 27, 2011 IP
  2. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #2
    Try using the following mod_rewrite rules:

    RewriteCond %{QUERY_STRING} ^lang=fr$
    RewriteRule ^(.*)$ http://mywebsite.com/mypage? [R=301,L]

    Or, use the following mod_rewrite rules (removes the "lang=fr" query parameter from all requested URL-paths):

    RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?]*\?(([^&]*)&)*lang=fr(&[\ ]*)?\ HTTP/
    # accept optional parameters before 'lang=fr', but none after
    RewriteCond %{QUERY_STRING} ^(([^&]*(&[^&]*)*)&)?lang=fr$ [OR]
    # require parameters before and accept optional parameters after 'lang=fr'
    RewriteCond %{QUERY_STRING} ^(([^&]*(&[^&]*)*)&)lang=fr((&[^&]*)*)$
    RewriteRule ^(.*)$ http://mywebsite.com/$1?%2%4 [R=301,L]
     
    RoseHosting, Apr 27, 2011 IP
  3. enetcloud-ceo

    enetcloud-ceo Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    Solution provided by Rosehosting should work and fix the issue.
     
    enetcloud-ceo, May 1, 2011 IP
  4. amarillo

    amarillo Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi,

    I've found this post while I was browsing the Web for a similar issue. Maybe someone here could help me solve it?

    On my website, I have a few URL that look like this: website.com/page?param=1 and they all give a 404 error.

    I don't want to remove the parameters but just ignore them to avoid the 404 error. How can I do this with htaccess?

    Here is my current .htaccess file:
    SetEnv PHP_VER 5
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php
    Code (markup):
    Sincerely,
    Amarillo
     
    amarillo, Aug 12, 2011 IP