SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    HTACCESS File Has Absolutely No Impact

    Hi,

    I have a detailed htaccess file which I was looking to edit. I made some changes to it and found that now changes were occuring ot my site. So I deleted the file outright and yet my site operates in completely the same way without the htaccess file.

    The confusing thing is that I have to have the htaccess file built for the purposes I was looking to be done.


    Code:
    Options -Indexes
    Options -MultiViews
    Options +FollowSymLinks
    
    # Prevent viewing of htaccess file
    <Files ~ "^\.ht">
    order allow,deny
    deny from all
    satisfy all
    </Files>
    
    # Disable directory listing from this point
    Options -Indexes
    
    
    # Error Pages
    ErrorDocument 404 /404-error.php
    
    # Rewrite Rules
    <IfModule mod_rewrite.c>
    RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
      RewriteRule ^products/(.*)/(.*)$ products/$1.php?product_id=$2 [QSA,L]
      RewriteRule ^products/nameproductscategorised/(.*)$ products/nameproductscategorised.php?linkname=$1&name=$1 [QSA,L]
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
      RewriteRule ^articles/article/([0-9]+)/(.*)$ articles/article.php?ID=$1 [QSA,L]
        RewriteRule ^articles/articlesfiltered/([A-Za-z]+)/(.*)$ articles/articlesfiltered.php?articlecategory=$1 [QSA,L]
      RewriteRule ^plusstyle/plusstyle/([0-9]+)/(.*)$ plusstyle/plusstyle.php?ID=$1 [QSA,L]
       RewriteRule ^plusstyle/plusstylesfiltered/([A-Za-z]+)/(.*)$ plusstyle/plusstylesfiltered.php?articlecategory=$1 [QSA,L]
         RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [QSA,L]
    	   RewriteRule ^products/roomproductscategorised/(.*)$ products/roomproductscategorised.php?room=$1 [QSA,L]
    </IfModule>

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,626
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Are you on Wordpress! Or a dedicated server? And Clear cache

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    A quick and ugly way to check if an .htaccess file is being loaded is to put an obvious error in it. For example, put
    Code:
    adsf
    as the first line. If that file is being loaded, your site will not work at all (that's the ugly part).

    This is really more of a server config question though you may find some help in this PHP forum. There are a number of reasons the file isn't being loaded by apache: it's in the wrong place or you're looking at the wrong .htaccess file, permissions of the file are wrong, the server is configured not to use them, file is named wrong.

    So first I would find out if the file you're looking at is being loaded at all. See my ugly check above.
    - Robert

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,605
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    PT - this is NOT WP code.

    JLU,

    PT is correct about the cache and QM's test will show whether your .htaccess is being parsed (it should throw a 500 error if it is).

    As for your code, though, a few comments might help you.

    Code:
    Options -Indexes
    Options -MultiViews
    Options +FollowSymLinks
    
    # Prevent viewing of htaccess file
    <Files ~ "^\.ht">
    order allow,deny
    deny from all
    satisfy all
    </Files>
    
    # Disable directory listing from this point
    Options -Indexes
    
    # Error Pages
    ErrorDocument 404 /404-error.php
    
    # Rewrite Rules
    <IfModule mod_rewrite.c>
    # Make this test ONCE, NOT multiple times for every file request!!!
    RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    # End of RewriteCond test effect, i.e., they were ONLY associated with this RewriteRule
    
      RewriteRule ^products/(.*)/(.*)$ products/$1.php?product_id=$2 [QSA,L]
    # This is a "catch-all" which will prevent the next two RewriteRules from being matched
    
      RewriteRule ^products/nameproductscategorised/(.*)$ products/nameproductscategorised.php?linkname=$1&name=$1 [QSA,L]
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    
      RewriteRule ^articles/article/([0-9]+)/(.*)$ articles/article.php?ID=$1 [QSA,L]
      RewriteRule ^articles/articlesfiltered/([A-Za-z]+)/(.*)$ articles/articlesfiltered.php?articlecategory=$1 [QSA,L]
    
      RewriteRule ^plusstyle/plusstyle/([0-9]+)/(.*)$ plusstyle/plusstyle.php?ID=$1 [QSA,L]
      RewriteRule ^plusstyle/plusstylesfiltered/([A-Za-z]+)/(.*)$ plusstyle/plusstylesfiltered.php?articlecategory=$1 [QSA,L]
    
      RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [QSA,L]
    # Not necessary within a character range definition.
    # Because it's a metacharacter within a character range definition, best to put first (per Apache) but last works, too
    
      RewriteRule ^products/roomproductscategorised/(.*)$ products/roomproductscategorised.php?room=$1 [QSA,L]
    </IfModule>
    In general, proceed from the most specific rule (set) to the most general to prevent "hijacking" of specific rules by the general rule.

    IF you need to skip all file and directories which exist, you can use the SKIP flag and logically invert your !-f/!-d tests, i.e.,

    Code:
    RewriteCond %{REQUEST_URI} -f [OR]
    RewriteCond %{REQUEST_URI} -d
    RewriteRule .? - [S=10]
    ... then continue with just your 10 RewriteRules.

    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


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
  •