The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Technical SEO Issues
    4. Htaccess file

    Htaccess file

    Technical SEO Issues
    5 5 437
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • semer
      semer last edited by

      I need to  redirect the web pages which do not exist  to 404 error

      the task need to be done in htaccess file.

      I am using Linux server.

      the webpages I want to redirect is my domain name followed by question mark

      e.g. www.mydomain.com/?dfdds

      I am using the following snippet in my htaccess file, it redirect to bing.com so far,

      please tell me how to change the snippet so that it redirect to redirect to 404 error page.

      ==========================

      RewriteCond %{QUERY_STRING} .

      RewriteRule .* http://www.bing.com? [L,R]

      1 Reply Last reply Reply Quote 0
      • Vizergy
        Vizergy last edited by

        This should help you:

        http://webdesignandsuch.com/create-a-htaccess-file-to-redirect-to-a-404-html-page/

        1 Reply Last reply Reply Quote 0
        • Jinx14678
          Jinx14678 last edited by

          I am not completely sure I get the question -

          two ways I interpreted - the easiest would just be the redirect /? to 404

          which would be

          redirect 301 /? http://www.404pagehere.com

          If you are trying to do a wildcard redirect that is a little harder

          RedirectMatch 301 /?/(.*)$ http://www.404pagehere.com

          I think the easiest might be

          RewriteEngine On
          RewriteRule ^foldername/* http://www.pagehere.com/ [R=301,L]

          Make sure and backup .htaccess before making any changes, as I am not sure what I gave you will fix your specific issue.

          Shane

          1 Reply Last reply Reply Quote 0
          • GeorgeAndrews
            GeorgeAndrews last edited by

            The reason your URL is redirecting to bing.com is you haven't changed the URL from the snippet you found to the URL you actually want to use as your 404 Error Page.

            You can create a 404 Error Page and place it on your server. If you have already done this you need to change the URL (http://www.bing.com) in the snippet below to the URL you want to use (e.g. http://www.[yourdomainname].com/404.html).

            RewriteCond %{QUERY_STRING} .

            RewriteRule .* http://www.bing.com? [L,R]

            That should look more like this:

            RewriteCond %{QUERY_STRING} .

            RewriteRule .* http://www.[yourdomainname].com/404.html [L,R=301]

            1 Reply Last reply Reply Quote 0
            • DMGoo
              DMGoo last edited by

              Use:

              ErrorDocument 404 /404.html

              where 404.html is your error document page!  If the page does not exist then it should return a 404 status code and then automatically redirect to this page.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              • Where to put 301 redirects in my Wordpress htaccess file?
                Benspain
                Benspain
                0
                3
                34

              • Search Console rejecting XML sitemap files as HTML files, despite them being XML
                SearchDeploy
                SearchDeploy
                0
                5
                89

              • Can someone interpret this entry in my htaccess file into english so that I can understand?
                cathibanks
                cathibanks
                0
                17
                199

              • Help creating a 301 redirect in my htaccess file
                Felip3
                Felip3
                0
                4
                108

              • Why are my URL's with a trailing slash still getting indexed even though they are redirected in the .htaccess file?
                irvingw
                irvingw
                0
                3
                288

              • Kill your htaccess file, take the risk to learn a little
                KevinBudzynski
                KevinBudzynski
                0
                2
                373

              • How should I properly setup my .htaccess file?
                maxduveen
                maxduveen
                0
                5
                2.0k

              • Converting files from .html to .php or editing .htaccess file
                donford
                donford
                0
                11
                3.6k

              Get started with Moz Pro!

              Unlock the power of advanced SEO tools and data-driven insights.

              Start my free trial
              Products
              • Moz Pro
              • Moz Local
              • Moz API
              • Moz Data
              • STAT
              • Product Updates
              Moz Solutions
              • SMB Solutions
              • Agency Solutions
              • Enterprise Solutions
              • Digital Marketers
              Free SEO Tools
              • Domain Authority Checker
              • Link Explorer
              • Keyword Explorer
              • Competitive Research
              • Brand Authority Checker
              • Local Citation Checker
              • MozBar Extension
              • MozCast
              Resources
              • Blog
              • SEO Learning Center
              • Help Hub
              • Beginner's Guide to SEO
              • How-to Guides
              • Moz Academy
              • API Docs
              About Moz
              • About
              • Team
              • Careers
              • Contact
              Why Moz
              • Case Studies
              • Testimonials
              Get Involved
              • Become an Affiliate
              • MozCon
              • Webinars
              • Practical Marketer Series
              • MozPod
              Connect with us

              Contact the Help team

              Join our newsletter
              Moz logo
              © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
              • Accessibility
              • Terms of Use
              • Privacy