• Resolved Jay

    (@the_circle_pit)


    How do you not allow access to a URL directory?

    For example. I do not want to show https://www.web.com/portfolio recursively, but i still want to use the portfolio items via a plugin. Any idea what I would put for the .htaccess to restrict this access? also which directory to put that .htaccess in?

Viewing 5 replies - 1 through 5 (of 5 total)
  • I think this will work from your root folder and be recursive, but I have in the past used something similar for protection in folders farther down the line:

    # add to /portfolio/ folder
    ## 0ption: set permissions to 0404
    # Whitelist all portfolio files
    SetEnvIf Request_URI "/portfolio/(.*).php$" whitelist
    # Whitelist ONLY one or more specific files
    #SetEnvIf Request_URI "/portfolio/filename.php$" whitelist
    #SetEnvIf Request_URI "/portfolio/filename.php$" whitelist
    #SetEnvIf Request_URI "/portfolio/filename.php$" whitelist
    #SetEnvIf Request_URI "/portfolio/filename.php$" whitelist
    #SetEnvIf Request_URI "/portfolio/filename.php$" whitelist
    <FilesMatch "\.(php)$">
    Order Deny,Allow
    Allow from env=whitelist
    Deny from all
    </FilesMatch>
    <Files ~ ".*\..*">
    order allow,deny
    deny from all
    </Files>
    <Files *.php>
    deny from all
    </Files>

    note: No guarantees of any kind here, just trying to be helpful!

    Thread Starter Jay

    (@the_circle_pit)

    Thanks for your reply, before your reply I tried to use a Rewrite Rule in my .htaccess of root dir. Which worked for me.

    Below is the rule:
    RewriteRule ^portfolio/ https://www.thecirclepit.com [R=301,L]

    It worked, but It also place the https://www.website.com in front of the links in the items execepts of those portfolio items.

    So now all the links are
    https://www.website.com/https://www.website.com/tag/example
    and
    https://www.website.com/www.facebook.com

    Any idea if there a way to remove the first section(https://www.website.com/) of those URL’s?

    I have only ever seen that once, and it was related to a 404 that was of no concern. So, I only know there must be a way and that here is where I would begin looking and trying to learn more:

    https://perishablepress.com/stupid-htaccess-tricks/

    https://corz.org/server/tricks/htaccess.php

    Thread Starter Jay

    (@the_circle_pit)

    The rewrite rule i used [R=301] is a Redirect and the 301 means Moved Permanently. Thats why there would be a 404 error. There has to be an easy way to undo this…

    [R] = instructs Apache to issue a redirect, causing the browser to request the rewritten/modified URL.

    Thread Starter Jay

    (@the_circle_pit)

    I ended up doing this…

    RedirectMatch 302 /portfolio/(.*) https://www.web.com/?s=$1
    Redirect 302 /portfolio https://www.web.com/

    Than change the 302 to 301 after testing.

    Also the ?s= from the first line is how my search works so it places any item that is typed after the /portfolio/ into a search for my site.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘htaccess directoy specific restriction’ is closed to new replies.