1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

RedirectMatch Strip Trailing ? From Redirect

Discussion in 'Apache' started by potentdevelopment, Mar 15, 2019.

  1. #1
    Hello,

    I have this rule in my .htaccess file:
    RedirectMatch 301 ^/browser-sync/browser-sync-client.js /?

    which I'm using to redirect this: /browser-sync/browser-sync-client.js?v=2.18.13

    After searching the web, I found info which said to add "?" to the redirect to remove the query string. Now, the query string is removed, but the ? remains. How can I remove both the query string and the ?.

    Currently the redirect above will do this: http://somedomain.com/?
    I want it to just redirect like this: http://somedomain.com/

    Thanks You
     
    potentdevelopment, Mar 15, 2019 IP
  2. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #2
    In Apache 2.4 or newer you can use the QSD (query string discard).

    
    RewriteEngine On
    RewriteCond %{QUERY_STRING} v=(.*)
    RewriteRule ^/browser-sync/browser-sync-client.js / [R=301,L,QSD]
    
    Code (markup):
     
    RoseHosting, Mar 15, 2019 IP
  3. potentdevelopment

    potentdevelopment Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Hi thanks for this.

    But unfortunately still having issues. I seem to be having an issue where only root level items are redirecting. For example:

    This works: RewriteRule ^/oranges.html$ /apples.html? [R=301,L]
    This does not works: RewriteRule ^/browser-sync/oranges.html$ /apples.html? [R=301,L]

    Any ides what could the issue?
     
    potentdevelopment, Mar 17, 2019 IP
  4. hostechsupport

    hostechsupport Well-Known Member

    Messages:
    413
    Likes Received:
    23
    Best Answers:
    7
    Trophy Points:
    138
    #4
    It should work you only need RewriteEngine On once at the top of your .htaccess You should add the www redirect to the top of your code and remove the L flag (see Removing the Slash)
     
    hostechsupport, Mar 19, 2019 IP