SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member saudiqbal's Avatar
    Join Date
    Feb 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question block some pages with htaccess

    I used to have php script which made dynamic pages like this.

    domain.com/?keyword-one,23
    domain.com/?another-keyword,43
    domain.com/?one-more-keyword,23
    and so on

    the problem is that I have removed the script from my server and I have static html pages like index.html and the above pages are still works because of that ? after the first / because the server is attaching those files as domain.com/index.html?keyword-one,23

    They are all indexed by search engines and I dont want 50 duplicate content from my index.html pages cuz all the above pages displays default html page /? <- because of that.

    is there any way to show error 410 gone using htaccess?

    I used RewriteRule ^index.html$ - [R=404,L,NC] and it is not working.

    Then I tried RewriteRule ^/?$ - [R=410,L,NC] and it works but if I type www.domain.com then I get the error page and it does not open default index.html page.

    Is it possible if the url contains ? then just throw a 410 page?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    saudi,

    Your first error was in not specifying the file which was handling your query string. LAZY links like this DO cause problems (using the DirectoryIndex) and now you're paying the price.

    Assuming that you've deleted all the files associated with your keywords, you have several options:

    1. First, if you're only using static webpages (.html), then simply delete all query strings with code like

      Code:
      RewriteCond %{QUERY_STRING} >' '
      RewriteRule .? %{REQUEST_URI}? [R=301,L]
      That will remove EVERY query string.
    2. If you have other script which require a query string, you can remove the query string on the index.html file with code like

      Code:
      RewriteCond %{QUERY_STRING} >' '
      RewriteRule ^index\.html$ %{REQUEST_URI}? [R=301,L]
    3. You COULD list your keywords but why when the above will work efficiently?


    As for your ErrorDocument, you have a problem because /?key=-value is specifying the DirectoryIndex and that's what you're providing, i.e., 404 is not correct. Since you're providing index.html, I'd recommend that you let the visitors figure that out for themselves.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Member saudiqbal's Avatar
    Join Date
    Feb 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks dklynn, this code is working fine.

    Code:
    RewriteCond %{QUERY_STRING} >''
    RewriteRule .? %{REQUEST_URI}? [R=410,L]
    I m now returning error 410 for all pages with domain.com/?keyword

    Tip: never hide the file name like index.php or you ll be having trouble with SEO. Once you delete your file they will still be indexed like domain.com/index.html?keyword


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •