可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答1:
RewriteCond %{REQUEST_URI} !^/(csNewsAd|csNewsAd/.*)$
instead of
RewriteRule ^/csNewsAd($|/) - [L]
回答2:
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.
回答3:
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
回答4:
.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.
回答5:
If you’re using mod_rewrite in a .htaccess file, you just need to specify the URL path without the local path prefix in your patterns. In your case without the leading /
(as you’re in the document root /
):
RewriteRule ^csNewsAd($|/) - [L]
回答6:
I first started doing this with Rails. At the top of the rails .htaccess are the following two lines.
# RewriteCond %{REQUEST_URI} ^/notrails.*
# RewriteRule .* – [L]
When I finally followed their example it worked.
I wanted to exclude images, javascripts, stylesheets, css, images-global, js-global (etc) so I changed the above to.
RewriteCond %{REQUEST_URI} ^(images|javascripts|stylesheets|css|images-globa|js-global|js).*
RewriteRule .* – [L]
And it worked the way I needed.
We won’t talk about how it is that I have so many different javascript, stylesheet and images folders….
But this does make my “error” file less painful. If someone adds an image file that doesn’t exist, my dispatch doesn’t have to process it.
回答7:
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]
So, that's my story. It works now. Thank you to Jory and GmonC!!! I upvoted you guys.
回答8:
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>
回答9:
you could add something like this:
RewriteCond %{REQUEST_URI} !^/csNewsAd
but this should not be needed, because if csNewsAd indeed is a directory (folder) it should not be rewritten in the first place because of
RewriteCond %{REQUEST_FILENAME} !-d
are you sure there isn't anything else sitting between you and that folder, rights or (indeed) another .htaccess?
回答10:
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
回答11:
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.
回答12:
It's worth noting that it matters where in the flow of the .htaccess this line goes.
See here : http://tanyanam.com/technology/wordpress-exclude-directory-from-url-rewrite-with-htaccess - the line needs to come before the WordPress ones, it won't work after them.
Rob
回答13:
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...
回答14:
This is the #1 google result and the wrong answer.
The correct answer is adding this before the Wordpress directives.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>