.htaccess & Wordpress: Exclude folder from Rewrite

2019-01-06 17:42发布

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 from another question similar here at SO, but didn't work at all.

AddHandler x-httpd-php5 .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/csNewsAd($|/) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Any suggestions?

More data

There's another .htaccess inside /csNewsAd for password protection:


AuthName "Clasificados"
AuthType "basic"
AuthUserFile /home/ig000192/public_html/csNewsAd/.passwd
Require valid-user

14条回答
Luminary・发光体
2楼-- · 2019-01-06 17:48

.htaccess affects all directories underneath, so if you put an .htaccess in csNewsAd with the rewrite directives you want, it will take precedence over the root file.

查看更多
再贱就再见
3楼-- · 2019-01-06 17:48

Here is my solution with regard to the GoDaddy WordPress site. My install had a web.config file so I added a rewrite rule. I wanted an /ApiData path where I could run an MVC.net application (virtual directory) for AJAX calls.

<system.webServer>
    <!-- ... -->
    <rewrite>
        <rules>
            <rule name="apidata" stopProcessing="true">
                <match url="apidata"/>
            </rule>
            <rule name="wordpress" patternSyntax="Wildcard">
                <match url="*"/>
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                </conditions>
                <action type="Rewrite" url="index.php"/>
            </rule>

        </rules>
    </rewrite>
</system.webServer>
查看更多
三岁会撩人
4楼-- · 2019-01-06 17:50

I'm pretty sure that you have already ruled this out, but since I came here for the same exact issue I wanted to share it with you: in my case the problem was actually on the permissions of - apparently, not being able to access the folder, the exclusion was being ignored.

查看更多
乱世女痞
5楼-- · 2019-01-06 17:51

Place the line below in the .htaccess file in the root.

ErrorDocument 401 default

Had the exact same problem and this worked for me. It is not the problem that the redirects don't work. The problem is that the 401 (Authorization Required) error is nog defined so the "popup" doesn't show.

查看更多
淡お忘
6楼-- · 2019-01-06 17:52

Was having the same issue and found the answer to my problem here: http://kb.siteground.com/article/How_to_exclude_a_folder_from_Wordpress_permalinks.html

--From the site

To exclude the subfolders from the WordPress rewrite rules, you need to edit the .htaccess file and change the bold line below:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule . /index.php [L] # Original line
RewriteRule ./ /index.php [L] # New line
</IfModule>
# END WordPress
查看更多
【Aperson】
7楼-- · 2019-01-06 17:52

I know its an old post, but it still helped me. I had the additional problem of several blocks of RewriteRules:

##
## White listed folders
##
RewriteCond %{REQUEST_URI} !^/(phplist|phplist/.*)$
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/.well-known/*
RewriteCond %{REQUEST_FILENAME} !/storage/app/uploads/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/media/.*
...
RewriteCond %{REQUEST_FILENAME} !/modules/.*/(assets|resources)/.*
RewriteRule !^index.php index.php [L,NC]

##
## Block all PHP files, except index
##
RewriteCond %{REQUEST_URI} !^/(phplist|phplist/.*)$
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !^index.php index.php [L,NC]

##
## Standard routes
##
RewriteCond %{REQUEST_URI} !^/(phplist|phplist/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

and had to add my RewriteCond before every block...

查看更多
登录 后发表回答