SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess rewrite

    I want to prohibit anyone from directly accessing files in a particular directory and was planning to use .htaccess rewrite rules. The directory I wish to protect is www.domain.com/ebookshop/pay2see and I was going to redirect anyone trying to access files in the pay2see directory to www.domain.com/ebookshop/pay2see.html
    I thought the following would do the trick but it appears not:
    Code:
    RewriteRule ^pay2see/?$ /ebookshop/pay2see.html [PT,L]
    Can anyone help please? Thanks G
    blessed are the cracked for they let in the light

  2. #2
    Non-Member
    Join Date
    Jul 2013
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do this via htaccess. Or another easy way is to just password protect the folder via your cpanel. And no google cant see it either.

  3. #3
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,154
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gandalf458 View Post
    ^pay2see/?$
    The problem is this pattern will match only /pay2see/, not /pay2see/some-path or /pay2see/some-path/more-path. If you want to match "pay2see" plus any paths underneath it, then you'll have to write it like this:

    ^pay2see(?:/.*)?$

    Or, alternatively:

    ^pay2see(?:/|$)

    Also, it matters where the htaccess file lives. All these patterns will work only if the htaccess file is inside "ebookshop". If, instead, your htaccess file lives at the root, then you'll have to include "ebookshop" in the pattern.

    ^ebookshop/pay2see(?:/|$)
    "First make it work. Then make it better."

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah - thanks Jeff. I'll try that... G
    blessed are the cracked for they let in the light

  5. #5
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried
    Code:
    RewriteRule ^ebookshop/pay2see/?$ /ebookshop/pay2see.html [PT,L]
    as there are no subdirectories but it still doesn't seem to work. Am I being dense?
    blessed are the cracked for they let in the light

  6. #6
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the sake of completeness my entire .htaccess file is
    Code:
    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    RewriteRule ^ebookshop/pay2see/?$ /ebookshop/pay2see.php [PT,L]
    IndexIgnore *
    ErrorDocument 401 /401.php
    ErrorDocument 404 /404.php
    blessed are the cracked for they let in the light

  7. #7
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,154
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    And what's an example URL that you're accessing that you expect to match but isn't?
    "First make it work. Then make it better."

  8. #8
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    blessed are the cracked for they let in the light

  9. #9
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,154
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Actually the problem is still the same that I mentioned before. You're matching exactly /pay2see/ and not allowing for anything to come after in the URL.
    "First make it work. Then make it better."

  10. #10
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah - thanks. I thought that was only if I had subdirectories. All working now.

    Thanks again
    G
    blessed are the cracked for they let in the light


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
  •