Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Question .htaccess and order of code?

    How do I know that I placed the correct code in the right places in the .htaccess file?

    Anyone able to assist me in checking my .htaccess file and seeing if it's correct?

    Cheers

  2. #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    377
    Thanks
    0
    Thanked 26 Times in 26 Posts
    How do I know that I placed the correct code in the right places in the .htaccess file?
    I believe the processing is done one module at a time. So for directives from different modules, the order usually does not matter. For example
    Code:
    ErrorDocument 404 /abc.html
    Redirect 302 /def http://www.example.com/ghi
    and
    Code:
    Redirect 302 /def http://www.example.com/ghi
    ErrorDocument 404 /abc.html
    do the same thing.

    for rules within some modules it might make a difference
    Code:
    RedirectMatch 302 ^/abc http://www.example.com/ghi
    RedirectMatch 302 ^/a http://www.example.com/jkl
    will redirect /abc to /ghi and
    Code:
    RedirectMatch 302 ^/a http://www.example.com/jkl
    RedirectMatch 302 ^/abc http://www.example.com/ghi
    will redirect /abc to /jkl.

    But it might not make a difference
    Code:
    ErrorDocument 404 /404.html
    ErrorDocument 401 /401.html
    Anyone able to assist me in checking my .htaccess file and seeing if it's correct?
    Post it.

  3. #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Attached is a copy of my .htaccess file that I currently use (domain shown as example.com)
    Last edited by student101; 06-13-2009 at 09:44 PM.

  4. #4
    Regular Coder
    Join Date
    Oct 2004
    Posts
    377
    Thanks
    0
    Thanked 26 Times in 26 Posts
    There's nothing major wrong with it. There's nothing wrong (as far as i can see) with the order.

    You only need one
    Code:
    RewriteEngine On
    When processing should stop after a RewriteRule matches, the L flag should be used. For example where you are using F(orbidden) and G(one).
    Attached Files Attached Files

  5. Users who have thanked schleppel for this post:

    student101 (04-15-2009)

  6. #5
    Regular Coder
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Cool,
    I see you changed the IP.* to IP\., wasn't too sure of that format...

    Let me test your version, for some reason only Opera obeyed the blocking of my own IP address for testing.
    Edit:
    I must review your version of shorthand to my loooooooooong version and learn some more.

    Thank you.
    Last edited by student101; 04-15-2009 at 10:48 PM.

  7. #6
    Regular Coder
    Join Date
    Oct 2004
    Posts
    377
    Thanks
    0
    Thanked 26 Times in 26 Posts
    Let me test your version, for some reason only Opera obeyed the blocking of my own IP address for testing.
    HTTP_USER_AGENT is not the user's IP address (REMOTE_ADDR is). You are probably blocking because of a version number, for example
    Code:
    Mozilla/5.0 (Windows NT 5.1; U; en-GB; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.61
    could be blocked by
    Code:
    RewriteCond %{HTTP_USER_AGENT} 200.*
    I must review your version of shorthand to my loooooooooong version and learn some more.
    I combined
    Code:
    RewriteCond %{HTTP_REFERER} www.macedonia-tour-travel\.com [NC,OR]
    # ....etc...
    RewriteCond %{HTTP_REFERER} deepakbansal\.com
    into
    Code:
    RewriteCond %{HTTP_REFERER} (www\.macedonia-tour-travel\.com|...etc...|deepakbansal\.com) [NC]
    with regular expression alternation.

    I then combined
    Code:
    RewriteCond %{HTTP_REFERER} long regular expression [NC]
    RewriteRule .* - [G]
    and
    Code:
    RewriteCond %{HTTP_USER_AGENT} long regular expression [NC]
    RewriteRule .* - [G,L]
    with the OR RewriteCond flag
    Code:
    RewriteCond %{HTTP_REFERER} long regular expression [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} long regular expression [NC]
    RewriteRule .* - [G,L]

  8. #7
    Regular Coder
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Wow you know your .htaccess, pretty neat!
    I wanted to send bad-bots/spammers to my own 404 page but I think I need to set the AllowOverride or ask the host to change one of the Apache files to help.
    I haven't figured out what IfModule mod_rewrite.c means yet.
    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} ^$                                                              [OR]
    RewriteCond %{HTTP_USER_AGENT} ^.*(<|>|'|%0A|%0D|%27|%3C|%3E|%00).*                            [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} ^.*(HTTrack|clshttp|archiver|loader|email|nikto|miner|python).* [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} ^.*(winhttp|libwww\-perl|curl|wget|harvest|scan|grab|extract).* [NC]
    RewriteRule ^(.*)$ http://domain.tld/errorpage.php?error=404 [G,L] 
    </IfModule>

  9. #8
    Regular Coder
    Join Date
    Oct 2004
    Posts
    377
    Thanks
    0
    Thanked 26 Times in 26 Posts
    I wanted to send bad-bots/spammers to my own 404 page but I think I need to set the AllowOverride or ask the host to change one of the Apache files to help.
    Why (the AllowOverride part)? What problem are you having?

    I haven't figured out what IfModule mod_rewrite.c means yet.
    Directives inside an <IfModule> will only be processed if the module (in this case mod_rewrite) is loaded (or if it's !module if the module is not loaded).

  10. #9
    Regular Coder
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    I can't seem to get the error404 page to show.
    I only see the hosts error pages

    I attempted the code I posted above but it doesn't work.

  11. #10
    Regular Coder
    Join Date
    Oct 2004
    Posts
    377
    Thanks
    0
    Thanked 26 Times in 26 Posts
    Are you using a free host? They might be forcing their pages so they can put ads on them.

  12. #11
    Regular Coder
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    No, it's paid hosting, no ads just this;
    Gone
    The requested resource
    /
    is no longer available on this server and there is no forwarding address. Please remove all references to this resource.
    Apache/2.2.3 (CentOS) Server at www.example.com Port 80

  13. #12
    Regular Coder
    Join Date
    Oct 2004
    Posts
    377
    Thanks
    0
    Thanked 26 Times in 26 Posts
    Oh i see. Try adding an ErrorDocument
    Code:
    ErrorDocument 410 /errorpage.php?error=404

  14. #13
    Regular Coder
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Ok it's the correct code for the "gone" page.
    Cool, thanks!
    Edit: No, for some reason that doesn't work.
    Last edited by student101; 04-17-2009 at 07:57 PM.

  15. #14
    Regular Coder
    Join Date
    Oct 2004
    Posts
    377
    Thanks
    0
    Thanked 26 Times in 26 Posts
    It works fine for me, what is your full .htaccess file?

    You could use
    Code:
    RewriteRule ^(.*)$ /errorpage.php?error=404 [L]
    and send the Gone header with PHP's header().

  16. #15
    Regular Coder
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    It's the exact same one you posted back.
    If I use: [F,L] I Get Apache 2 Test Page
    If I use: [G,L] or [L] I Get this:
    Gone
    The requested resource
    /
    is no longer available on this server and there is no forwarding address. Please remove all references to this resource.
    Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.


 
Page 1 of 2 12 LastLast

Posting Permissions

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