Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13

    2 .htaccess files need to work together


    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?html=%{REQUEST_FILENAME} [L,PT,QSA]
    I have the above directive to rewrite all .html requests to 'counter.py' script.
    Counter.py does logging of each .html page requested.
    That works for many websites iam trying to log as expected.
    Preoblem is that some websites have been created by Joomla and they have their own Joomla .htaccess file which is needed if they are to work properly.

    So i don't really know how to use my .htaccess directives along with Joomla's .htaccess file which is like the following:

    Code:
    ##
    # @version $Id: htaccess.txt 21064 2011-04-03 22:12:19Z dextercowley $
    # @package Joomla
    # @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
    # @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
    # Joomla! is Free Software
    ##
    
    #####################################################
    #  READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
    #
    # The line just below this section: 'Options +FollowSymLinks' may cause problems
    # with some server configurations.  It is required for use of mod_rewrite, but may already
    # be set by your server administrator in a way that dissallows changing it in
    # your .htaccess file.  If using it causes your server to error out, comment it out (add # to
    # beginning of line), reload your site in your browser and test your sef url's.  If they work,
    # it has been set by your server administrator and you do not need it set here.
    #
    #####################################################
    
    ##  Can be commented out if causes errors, see notes above.
    Options +FollowSymLinks
    
    #
    #  mod_rewrite in use
    
    RewriteEngine On
    
    ########## Begin - Rewrite rules to block out some common exploits
    ## If you experience problems on your site block out the operations listed below
    ## This attempts to block the most common type of exploit `attempts` to Joomla!
    #
    ## Deny access to extension xml files (uncomment out to activate)
    #<Files ~ "\.xml$">
    #Order allow,deny
    #Deny from all
    #Satisfy all
    #</Files>
    ## End of deny access to extension xml files
    # Block out any script trying to set a mosConfig value through the URL
    RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
    # Block out any script trying to base64_encode data within the URL
    RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
    # Block out any script that includes a <script> tag in URL
    RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
    # Block out any script trying to set a PHP GLOBALS variable via URL
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    # Block out any script trying to modify a _REQUEST variable via URL
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    # Return 403 Forbidden header and show the content of the root homepage
    RewriteRule .* index.php [F]
    #
    ########## End - Rewrite rules to block out some common exploits
    
    ########## Begin - Custom redirects
    #
    # If you need to redirect some pages, or set a canonical non-www to
    # www redirect (or vice versa), place that code here. Ensure those
    # redirects use the correct RewriteRule syntax and the [R=301,L] flags.
    #
    ########## End - Custom redirects
    
    #  Uncomment following line if your webserver's URL
    #  is not directly related to physical file paths.
    #  Update Your Joomla! Directory (just / for root)
    
    # RewriteBase /
    
    ########## Begin - Joomla! core SEF Section
    #
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    #
    # If the requested path and file is not /index.php and the request
    # has not already been internally rewritten to the index.php script
    RewriteCond %{REQUEST_URI} !^/index\.php
    # and the request is for root, or for an extensionless URL, or the
    # requested URL ends with one of the listed extensions
    RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
    # and the requested path and file doesn't directly match a physical file
    RewriteCond %{REQUEST_FILENAME} !-f
    # and the requested path and file doesn't directly match a physical folder
    RewriteCond %{REQUEST_FILENAME} !-d
    # internally rewrite the request to the index.php script
    RewriteRule .* index.php [L]
    #
    ########## End - Joomla! core SEF Section
    
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>
    
    deny from 89.210.12.89
    deny from 77.49.228.143
    Please help me use my counter.py logging script along with these Joomla websites too. Thank you.
    What is now proved was once only imagined!
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,183
    Rep Power
    9398
    As you have it now Joomla is only configured to handle requests for things that don't exist. The code you're trying to add is only for things that do exist. The two do not conflict: simply add the code in.
  4. #3
  5. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13
    Jomla's .htaccess is located at:
    /home/nikos/public_html/radio-klepsydra/ which is the add-on domain folder for radio-klepsydra.com

    I have embedded "my" 2 lines of code in the beginning of Joomla's .htaccess but the .htmls never get redirected to my counter.py.

    Also Joomla's .htaccess have some rewrite rules of their own, are you sure they never interfere?



    Code:
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?html=%{REQUEST_FILENAME} [L,PT,QSA]
    
    ##
    # @version $Id: htaccess.txt 21064 2011-04-03 22:12:19Z dextercowley $
    # @package Joomla
    # @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
    # @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
    # Joomla! is Free Software
    ##
    
    #####################################################
    #  READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
    #
    # The line just below this section: 'Options +FollowSymLinks' may cause problems
    # with some server configurations.  It is required for use of mod_rewrite, but may already
    # be set by your server administrator in a way that dissallows changing it in
    # your .htaccess file.  If using it causes your server to error out, comment it out (add # to
    # beginning of line), reload your site in your browser and test your sef url's.  If they work,
    # it has been set by your server administrator and you do not need it set here.
    #
    #####################################################
    
    ##  Can be commented out if causes errors, see notes above.
    Options +FollowSymLinks
    
    #
    #  mod_rewrite in use
    
    RewriteEngine On
    
    ########## Begin - Rewrite rules to block out some common exploits
    ## If you experience problems on your site block out the operations listed below
    ## This attempts to block the most common type of exploit `attempts` to Joomla!
    #
    ## Deny access to extension xml files (uncomment out to activate)
    #<Files ~ "\.xml$">
    #Order allow,deny
    #Deny from all
    #Satisfy all
    #</Files>
    ## End of deny access to extension xml files
    # Block out any script trying to set a mosConfig value through the URL
    RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
    # Block out any script trying to base64_encode data within the URL
    RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
    # Block out any script that includes a <script> tag in URL
    RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
    # Block out any script trying to set a PHP GLOBALS variable via URL
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    # Block out any script trying to modify a _REQUEST variable via URL
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    # Return 403 Forbidden header and show the content of the root homepage
    RewriteRule .* index.php [F]
    #
    ########## End - Rewrite rules to block out some common exploits
    
    ########## Begin - Custom redirects
    #
    # If you need to redirect some pages, or set a canonical non-www to
    # www redirect (or vice versa), place that code here. Ensure those
    # redirects use the correct RewriteRule syntax and the [R=301,L] flags.
    #
    ########## End - Custom redirects
    
    #  Uncomment following line if your webserver's URL
    #  is not directly related to physical file paths.
    #  Update Your Joomla! Directory (just / for root)
    
    # RewriteBase /
    
    ########## Begin - Joomla! core SEF Section
    #
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    #
    # If the requested path and file is not /index.php and the request
    # has not already been internally rewritten to the index.php script
    RewriteCond %{REQUEST_URI} !^/index\.php
    # and the request is for root, or for an extensionless URL, or the
    # requested URL ends with one of the listed extensions
    RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
    # and the requested path and file doesn't directly match a physical file
    RewriteCond %{REQUEST_FILENAME} !-f
    # and the requested path and file doesn't directly match a physical folder
    RewriteCond %{REQUEST_FILENAME} !-d
    # internally rewrite the request to the index.php script
    RewriteRule .* index.php [L]
    #
    ########## End - Joomla! core SEF Section
    
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>
    
    deny from 89.210.12.89
    deny from 77.49.228.143
    What is now proved was once only imagined!
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,183
    Rep Power
    9398
    Originally Posted by Nik
    I have embedded "my" 2 lines of code in the beginning of Joomla's .htaccess but the .htmls never get redirected to my counter.py.
    Funny. I thought you posted three lines of code.

    RewriteCond and RewriteRule won't do anything if you don't use a RewriteEngine to enable rewriting beforehand.

    Originally Posted by Nik
    Also Joomla's .htaccess have some rewrite rules of their own, are you sure they never interfere?
    Why take my word for it? Learn what it does and form your own opinion.
  8. #5
  9. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?html=%{REQUEST_FILENAME} [L,PT,QSA]
    Even now that i have inserted the Rewrite Engine On it still doesnt rewrite the .html requests to counter.py script.

    Please help me as i'am confused and don't know how to handle this.
    What is now proved was once only imagined!
  10. #6
  11. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13
    please requinix give me some help with this.

    if i delete joomla's .htaccess file and replace it with my .htaccesss file that rewrite .html to counter.py sccript then joomla's site wont work properly.

    i need it to work properly and at the same time the .html pages be rewritten to my counter.py script.

    is this possible please?
    What is now proved was once only imagined!
  12. #7
  13. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,183
    Rep Power
    9398
    Assuming your new code is correct, I don't see any reason why it wouldn't work. Try using a different destination URL, with the [R] flag, to see whether it's triggering at all.
    Code:
    RewriteRule ^/?(.+\.html) /COUNTER/?html=%{REQUEST_FILENAME} [R,L,QSA]
    Also try without the RewriteCond to see if that's causing the problem. Then try without the search string in the Rule
    Code:
    RewriteRule ^ /COUNTER/?html=%{REQUEST_FILENAME} [R,L,QSA]
    to see if that works.
  14. #8
  15. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13
    I tried them all and the domain radio-klepsydra.com gives erros as the following:

    Code:
    Η ιστοσελίδα στη διεύθυνση http://www.radio-klepsydra.com/COUNTER/?html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/COUNTER&html=/home/nikos/public_html/radio-klepsydra.com/ είχε ως αποτέλεσμα να προκύψει μεγάλος αριθμός ανακατευθύνσεων. Η εκκαθάριση των cookie για αυτόν τον ιστότοπο ή η αποδοχή cookie τρίτου μέρους ενδέχεται να επιδιορθώσει το πρόβλημα. Εάν όχι, πρόκειται πιθανότατα για πρόβλημα με τη διαμόρφωση του διακομιστή και όχι με τον υπολογιστή σας.
    Is it because jooml's htaccess at some point bottown down it has rewrite rule for .php files as well?

    can an .htaccess file work with many rewrite rules?
    Last edited by Nik; January 29th, 2013 at 02:41 PM.
    What is now proved was once only imagined!
  16. #9
  17. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,183
    Rep Power
    9398
    No, it's my bad. It's an infinite loop.
    Code:
    RewriteRule ^(?!/?COUNTER)/?(.+\.html) /COUNTER/?html=%{REQUEST_FILENAME} [R,L,QSA]
    RewriteRule ^(?!/?COUNTER) /COUNTER/?html=%{REQUEST_FILENAME} [R,L,QSA]
  18. #10
  19. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13
    Same thing infinite loop: this is what i have tried:

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^(?!/?COUNTER)/?(.+\.html) /COUNTER/?html=%{REQUEST_FILENAME} [R,L,QSA]
    RewriteRule ^(?!/?COUNTER) /COUNTER/?html=%{REQUEST_FILENAME} [R,L,QSA]
    
    ##
    # @version $Id: htaccess.txt 21064 2011-04-03 22:12:19Z dextercowley $
    # @package Joomla
    # @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
    # @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
    # Joomla! is Free Software
    ##
    
    #####################################################
    #  READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
    #
    # The line just below this section: 'Options +FollowSymLinks' may cause problems
    # with some server configurations.  It is required for use of mod_rewrite, but may already
    # be set by your server administrator in a way that dissallows changing it in
    # your .htaccess file.  If using it causes your server to error out, comment it out (add # to
    # beginning of line), reload your site in your browser and test your sef url's.  If they work,
    # it has been set by your server administrator and you do not need it set here.
    #
    #####################################################
    
    ##  Can be commented out if causes errors, see notes above.
    Options +FollowSymLinks
    
    #
    #  mod_rewrite in use
    
    RewriteEngine On
    
    ########## Begin - Rewrite rules to block out some common exploits
    ## If you experience problems on your site block out the operations listed below
    ## This attempts to block the most common type of exploit `attempts` to Joomla!
    #
    ## Deny access to extension xml files (uncomment out to activate)
    #<Files ~ "\.xml$">
    #Order allow,deny
    #Deny from all
    #Satisfy all
    #</Files>
    ## End of deny access to extension xml files
    # Block out any script trying to set a mosConfig value through the URL
    RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
    # Block out any script trying to base64_encode data within the URL
    RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
    # Block out any script that includes a <script> tag in URL
    RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
    # Block out any script trying to set a PHP GLOBALS variable via URL
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    # Block out any script trying to modify a _REQUEST variable via URL
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    # Return 403 Forbidden header and show the content of the root homepage
    RewriteRule .* index.php [F]
    #
    ########## End - Rewrite rules to block out some common exploits
    
    ########## Begin - Custom redirects
    #
    # If you need to redirect some pages, or set a canonical non-www to
    # www redirect (or vice versa), place that code here. Ensure those
    # redirects use the correct RewriteRule syntax and the [R=301,L] flags.
    #
    ########## End - Custom redirects
    
    #  Uncomment following line if your webserver's URL
    #  is not directly related to physical file paths.
    #  Update Your Joomla! Directory (just / for root)
    
    # RewriteBase /
    
    ########## Begin - Joomla! core SEF Section
    #
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    #
    # If the requested path and file is not /index.php and the request
    # has not already been internally rewritten to the index.php script
    RewriteCond %{REQUEST_URI} !^/index\.php
    # and the request is for root, or for an extensionless URL, or the
    # requested URL ends with one of the listed extensions
    RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
    # and the requested path and file doesn't directly match a physical file
    RewriteCond %{REQUEST_FILENAME} !-f
    # and the requested path and file doesn't directly match a physical folder
    RewriteCond %{REQUEST_FILENAME} !-d
    # internally rewrite the request to the index.php script
    RewriteRule .* index.php [L]
    #
    ########## End - Joomla! core SEF Section
    
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>
    
    deny from 89.210.12.89
    deny from 77.49.228.143
    With or without the Rewrite Condition still creates an infinite loop.

    Whyt doesnt the .html requests get get redirected to the counter.py script?
    What is now proved was once only imagined!
  20. #11
  21. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,183
    Rep Power
    9398
    Conds only apply to the next Rule and not any more after.

    Looking at your URL, are you trying to go to a .html file that actually exists? Is not handled by Joomla?
  22. #12
  23. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13
    Originally Posted by requinix
    Conds only apply to the next Rule and not any more after.

    Looking at your URL, are you trying to go to a .html file that actually exists? Is not handled by Joomla?
    Actually i'am trying to go to http://www.radio-klepsydra.com/
    which is a Joomla website and it uses php code perhaps to create html pages.

    But even if i try directly http://www.radio-klepsydra.com/program.html which is a request to an html page STILL this specific .html request doesnt get redirected to the cg-bin/counter.py script of mine.

    Any other website i use that its not Joomla based and has only my kind of .htaccess file gets redirected to counter.py script properly.

    Only Joomla's websites are creating this issue.
    What is now proved was once only imagined!
  24. #13
  25. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,183
    Rep Power
    9398
    Try the other way around: screw Joomla, just use that rewrite stuff you have. Comment out/get rid of the rest.

    So just
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?html=%{REQUEST_FILENAME} [L,PT,QSA]
    Also, if I go to
    Code:
    http://www.radio-klepsydra.com/cgi-bin/counter.py?html=/home/nikos/public_html/radio-klepsydra.com/program.html
    I get an error (originating from the Python script).
  26. #14
  27. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13
    Originally Posted by requinix
    Try the other way around: screw Joomla, just use that rewrite stuff you have. Comment out/get rid of the rest.

    So just
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?html=%{REQUEST_FILENAME} [L,PT,QSA]
    I just tried it and leaved as you said deliberately for you to see to that if i use ONLY my .htaccess directives then only ONLY http://www.radio-klepsydra.com/ works and no other link to the page. if you try to click a link you will be displayed a 404 oage not found error. That indicates that Joomla's directives are there for a reson, to help Joomlaload its sub-pages/links properly.

    Originally Posted by requinix
    Also, if I go to
    Code:
    http://www.radio-klepsydra.com/cgi-bin/counter.py?html=/home/nikos/public_html/radio-klepsydra.com/program.html
    I get an error (originating from the Python script).
    indeed the python script says that it cannot open the file 'radio-klepsydra.com/program.html' .....

    When i try to locate the file within cPanel i also cannot found it myself as an existed file! BUT when i try to:

    http://radio-klepsydra.com/program.html then it loads normally!!

    I cannot make sense out of this!
    Last edited by Nik; January 29th, 2013 at 09:44 PM.
    What is now proved was once only imagined!
  28. #15
  29. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,284
    Rep Power
    13
    But this .html file which I CAN SEE inside cPanel displayes properly.

    http://radio-klepsydra.com/radio3.html

    and can also get redirected throught my pytho script as it can be shown here:

    http://radio-klepsydra.com/radio3.html?show=log
    What is now proved was once only imagined!
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo