.htaccess & WordPress: Exclude folder from RewriteRule

前端 未结 17 1542
不思量自难忘°
不思量自难忘° 2020-11-29 06:37

I have this .htaccess file in WordPress. It\'s located at /public_html/ (web root). I need to exclude a folder (csNewsAd) from the rewrite engine. I\'ve tried this, based fr

17条回答
  •  鱼传尺愫
    2020-11-29 07:06

    I have GoDaddy hosting, and this issue killed me. I had the same issues over and over again with conflicting .htaccess options in public_html, with my password-protected sub-directory.

    I ended up buying another account because I tried about a million different modifications to my .htaccess file, and nothind worked around this problem. I'm sharing my setup and solution, now, just for completeness and clarity. (Just so you know, the account was worth it anyway, so no biggie.)

    If it looks like a combination of other's answers, that's because it is. It took ALL of that to work.

    Directory structure:

    -otherfiles
    ---public_html
    ---.htaccess
    -----subfolder
    ---.htaccess
    

    The subfolder .htaccess has password the protect feature, so similar to this:

    AuthType Basic
    AuthName "Attendance"
    AuthUserFile "/home/user/.htpasswds/public_html/attendance/passwd"
    require valid-user
    

    The public_html .htaccess originally had this, and it wasn't working (in that it swallowed EVERYTHING and redirected it, so that FatFreeFramework or CodeIgniter was handling it):

    RewriteEngine On
    RewriteCond $1 !^(index.php|resources|subfolder|robots.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    

    In order to fix this problem, I added two lines to my public_html .htaccess file. And so you're not guessing as to where, I'll show the whole file again:

    RewriteEngine On
    RewriteCond $1 !^(index.php|resources|robots.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_URI} !^/(subfolder|subfolder/.*)$
    ErrorDocument 401 default
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    

提交回复
热议问题