排除.htaccess中的一个目录(不仅仅是重写规则)

发布于 2024-10-04 13:42:09 字数 729 浏览 1 评论 0原文

从 .htaccess 文件中的重写规则中排除一个或多个目录似乎是一个常见问题。然而,我的 .htaccess 不仅仅只是设置重写规则。我还设置了一些服务器更改(我们在此服务器上没有 suPHP)以及设置了一些 php 文件的前置。例如,以下是一些示例:

    # Make files ending in .php, .html and .xml files etc. parsed by php.
    AddType application/x-httpd-php .php .html .xml .css .js .le .txt

<FilesMatch "\.html$">
php_value auto_prepend_file "/home/2427/spwebsites/www.spwebsites.co.uk/incs/phps/config.php"
</FilesMatch>
# Internal Server Error
ErrorDocument 500 /admin/errors.html?code=500
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-]+)/$ $1.html [L]

我不想为一个目录(我的 word press 安装所在的目录)设置任何这些内容,有什么办法可以做到这一点?我可以为整个 .htaccess 文件设置条件语句吗?

在 wordpress 目录中添加空白 .htaccess 文件将不起作用,因为这不会撤消父目录中的设置。

Excluding one or more directories from rewrite rules in .htaccess files seems to be a common question. However, my .htaccess does more than just set rewrite rules. I've also set some server changes (we don't have suPHP on this server) as well as set some prepending of some php files. For example these are a few examples:

    # Make files ending in .php, .html and .xml files etc. parsed by php.
    AddType application/x-httpd-php .php .html .xml .css .js .le .txt

<FilesMatch "\.html$">
php_value auto_prepend_file "/home/2427/spwebsites/www.spwebsites.co.uk/incs/phps/config.php"
</FilesMatch>
# Internal Server Error
ErrorDocument 500 /admin/errors.html?code=500
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-]+)/$ $1.html [L]

I don't want any of these set for one directory (where my word press installation is), is there a way I can do this? Can I set a conditional statement for the whole .htaccess file?

Adding a blank .htaccess file in the word press directory won't work because this won't undo the settings in the parent directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫负雪 2024-10-11 13:42:09

我只是在研究你的困境,这是一个棘手的问题。如果能够在 .htaccess 中使用 DirectoryMatch 指令,那就太好了……

您可以尝试通过另一个 .htaccess 文件重置特定目录中的值。

因此,在 AddType 的情况下,将其重置回“.php”可能会起作用(假设它不继承其他值)。如果无法访问主配置文件/虚拟主机,这绝对不是一个理想的解决方案。

这里有一个奇怪的想法,您可以尝试/测试...将“wordpress”目录放置在主根之外(或任何有问题的 .htaccess 文件的地方)。现在将所有对 wordpress(内部目录)的请求路由到外部目录。我想知道考虑到请求正在被路由,Apache 是否不会使用有问题的 .htaccess?

I was just looking into your dilemma and it is a tricky one. It would be nice to be able to have the DirectoryMatch directive available in .htaccess ...

What you can try is to reset your values in the specific directory via another .htaccess file.

So in the case of the AddType perhaps, resetting it back to just ".php" might work (assuming it doesn't inherit the other values). Definitely not an ideal solution with out access to the main config file/ virtual host.

Here is a weird idea that you can try/test ... place the "wordpress" dir outside of the main root (or whereever you have the offending .htaccess file). Now route all requests to the wordpress (inner dir) to the outer dir. I wonder if Apache would not use the offending .htaccess considering the requests are being routed?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文