.htaccess & WordPress: Exclude folder from RewriteRule

前端 未结 17 1398
不思量自难忘°
不思量自难忘° 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:21

    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...

    0 讨论(0)
  • 2020-11-29 07:22

    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>
    
    0 讨论(0)
  • 2020-11-29 07:23

    You should try this one

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^/(gadget)/(.*) /gadget/$2 [R]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    0 讨论(0)
  • 2020-11-29 07:24

    try with this single rule :D please note that dashboard is the name of the directory I wanted to exclude so change that according to your needs.

    RewriteRule ^(dashboard)($|/) – [L]
    
    0 讨论(0)
  • 2020-11-29 07:24

    It seems to be that:

    ErrorDocument 401 default

    At the end of .htaccess

    is the correct answer. I tried a number of solutions but then had the brain wave to check it on another browser (safari) then cleared cache and hard reload of site on chrome gave positive result (amateur mistake). Darn that caching.

    On Mac (in Chrome) you need to 'control' click anywhere on the page. Then choose 'inspect' this will allow you then to 'control' click on the little circular arrow (re-fresh button) and it will give options - one is 'Empty cache and hard reload'. very useful for regaining sanity.

    0 讨论(0)
提交回复
热议问题