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:

    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
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,330
    Likes Received:
    1,709
    Best Answers:
    31
    Trophy Points:
    475
    #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