• Resolved marcusasiabc

    (@marcusasiabc)


    Hi there,

    WP has done a good afford on security, but I just get confused by the default .htaccess rules.

    I have a WP installed in the root directory (e.g. https://mysite.com/), I want to exclude a sub-directory (e.g. /mydir) and the file inside (e.g. /mydir/myfile.php) from re-write rule for direct access.

    I have changed file permission of myfile.php to 775.

    I hope that I can directly execute myfile.php by below url.
    https://mysite.com/mydir/myfile.php

    However, I got redirect to 404.

    I know it is a .htaccess issues, so I added below code in my .htaccess in root folder:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_URI} !^/mydir/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    May anyone has done it before? Any comments welcome. Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • @marcusasiabc, Put the below line on the top of your .htaccess

    ErrorDocument 401 default

    Thread Starter marcusasiabc

    (@marcusasiabc)

    Thanks for update, I have made the update in .htaccess accordingly but it seems that it made nothing changed. May I have your extra support?

    @marcusasiabc, Then try to replace your .htaccess with this code (remove everything else)

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^/yoursubdirectoryname1/(.*)$
    RewriteRule ^.*$ - [L]
    </IfModule>
    
    # BEGIN WordPress
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    * Replace yoursubdirectoryname1 with the appropriate value.

    Thread Starter marcusasiabc

    (@marcusasiabc)

    It works!

    @marcusasiabc, I am glad that we’ve fixed it finally ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘sub-directory from exclusion of redirect/rewrite (.htaccess tweak)’ is closed to new replies.