SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    -f parameter ignored?

    Can you help me find out what's wrong with this?

    I'm not an Apache programmer, one of the few things I thought I do know is that -f means "is not a file", which triggers when "not found", but now i doubt it.

    These are my rules, and the problem is that the verification file from google e.g. /8377rsomecode.html is not found (it's a real file, not a wordpress page)

    It should be NOT catched by line marked with ***********

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^blog/(.*)\.html http://%{SERVER_NAME}/$1 [R=301,L]
    #
    RewriteCond %{HTTP_HOST} =!blog/page/.*
    RewriteCond %{HTTP_HOST} =!blog/tag/.*
    RewriteCond %{HTTP_HOST} =!blog/category/.*
    RewriteRule ^blog/(.*) http://%{SERVER_NAME}/$1 [R=301,L]
    # remaining.html files
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)\.html$ /$1 [R=301,L]************
    #
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

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

    The -f will match a file which exists just as -d will match a directory which exists. The !-f and !-d negate these, i.e., if the request is neither a file nor directory, then ...

    Other problems:

    1. [rant #4]
    The definition of an idiot is someone who repeatedly does the same thing expecting a different result. Asking Apache to confirm the existence of ANY module with an <IfModule> ... </IfModule> wrapper is the same thing in the webmaster world. DON'T BE AN IDIOT! If you don't know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache's resources (and should NEVER be allowed on a shared server).
    [/rant 4]

    OMG! Not only do you make this test once but TWICE!

    2. What does "catched" (cached) have to do with mod_rewrite code?

    3. Other coding problems:

    Code:
    <IfModule mod_rewrite.c>
    # Where did this get closed?
    RewriteEngine On
    RewriteBase /
    # strip blog from URI
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^blog/(.*)\.html http://%{SERVER_NAME}/$1 [R=301,L]
    #
    # This code will never be matched/redirected as the above block will have removed blog/
    RewriteCond %{HTTP_HOST} =!blog/page/.*
    RewriteCond %{HTTP_HOST} =!blog/tag/.*
    RewriteCond %{HTTP_HOST} =!blog/category/.*
    RewriteRule ^blog/(.*) http://%{SERVER_NAME}/$1 [R=301,L]
    # remaining.html files
    # Strip .html extension from non-file requests
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)\.html$ /$1 [R=301,L]************
    #
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    # doesn't index.php exist? !-f will be sufficient
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? /index.php [L]
    # Handle empty request, too!
    </IfModule>
    
    # END WordPress
    [/QUOTE]

    From your use of "canned" code without understanding even the basics, I need to recommend the tutorial linked in my signature. It's helped others and should help your understanding. The sample code explanations should also help.

    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
    Join Date
    Oct 2011
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The -f will match…
    I know. No insults here?

    1- The definition of a Master idiot and Idiot-phobic is those who think other people is asking questions because they are idiots, and ignore there are other causes for the questions, like I'm not an Apache programmer, not a formal programmer at all. I just learned PHP and Basic and JavaScript and ActionScript by using it. Enough for me to still develop wordpress sites and "ask" for help, as the first line of the message said.

    1-a I didn't know there are a [rant] shortcode. You are very ingenious and have an original way to help. Would you help people who are not idiots? How do you tell? They speak proper english? Do you know only ONE language?

    1-b I'd rather open it and close it twice than messing with WP code, because everything inside #Begin WordPress comments will be overridden in the next page load.

    3- "Catched" wanted to be the past for "Catch", or the misspelling for "caught". Will you help people with grammar and spelling errors? Does your brain consider an idiot to everyone with less experience than you? Is there a limit? A quantum physics scientist asking for help to code his website with front-page (if still exists) is an idiot too? Should a person knowing one more language than you or cooking better barbecues than yours consider you an "idiot" if he/she had your stupid brain? ir is it a defect in DNA not related to a brain defect?

    # This code will never be matched/redirected as the above block will have removed blog/
    RewriteCond %{HTTP_HOST} =!blog/page/.*
    RewriteCond %{HTTP_HOST} =!blog/tag/.*
    RewriteCond %{HTTP_HOST} =!blog/category/.*
    RewriteRule ^blog/(.*) http://%{SERVER_NAME}/$1 [R=301,L]
    The code above this ( specifically ^blog/(.*)\.html ) was expected to remove blog/ ONLY to pages containing .html AND blog/ , and IT DID, but it was removing .html to ALL the requests, even the ones which didn't have bog/.
    I fixed it adding RewriteCond %{HTTP_HOST} =/blog/.* to the first rule and it totally works now.

    It was the main request of this topic and You totally missed it. I hope helps others.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    # doesn't index.php exist? !-f will be sufficient
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? /index.php [L]
    # Handle empty request, too!
    </IfModule>
    You can send a ticket to WordPress team with your narrow opinions so they can re-evaluate their world's-most-used cms platform for that last code. They must be idiots too.

    Thank you!

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

    I apologize for writing in a manner which you found offensive. I can assure you that offense was not intended and recommend that you look though the "offensive" words for all the useful information there.

    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


Tags for this Thread

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
  •