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.

htaccess - throw 404 if url/q string doesn't contain specific word

Discussion in 'Apache' started by ipunkbali, Sep 26, 2015.

  1. #1
    how to throw 404 if query string doesn't contain the word "news"
    all query string must contain "news"

    example:
    SEMrush
    mysite.com/index.php?q=obama-gossip-news ->Okay
    mysite.com/index.php?q=obama-gossip-etc ->redirect to 404.php

    thanks
     
    ipunkbali, Sep 26, 2015 IP
    SEMrush
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    6,234
    Likes Received:
    1,252
    Best Answers:
    22
    Trophy Points:
    400
    #2
    Since it's a query string you should do something like:

    
    RewriteCond %{QUERY_STRING} !news [NC]
    RewriteRule ^(.*)$ /404.php [L]
    
    Code (markup):
    If the word "news" is missing from the string it should redirect it to your error page.
     
    qwikad.com, Oct 5, 2015 IP