在我的Wordpress网站主目录中,我创建了一个文件夹servers, 其中包含两个文件.htaccess &;index.php.
在.htaccess 文件中,我添加这些行以将指向该文件夹的所有请求重定向到index.php 文件
# Enable rewriting.
RewriteEngine on
# Optional: do not allow perusal of directories.
Options -Indexes
# Optional: explicitly enable per-directory rewrites in the .htaccess context.
Options +FollowSymLinks
# Required when not in the webroot. Always use a trailing slash.
RewriteBase /
# To be able to access existing directories and files (standalone scripts).
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# Redirect everything else to index.php.
# Add QSA to ensure that querystring variables are registered as such.
RewriteRule . index.php [L,QSA]
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
所以每当用户请求链接时
example.com,
example.com/foo 或
example.com/foo/bar, 应加载默认Wordpress网站。当我请求任何以
servers 文件夹:
example.com/servers,
example.com/servers/foo,
example.com/servers/foo/bar, 我想要
example/com/servers/index.php 要执行的文件。
当前example.com/servers/.htaccess 文件仅执行此urlexample.com/servers 使用example.com/servers/index.php 但它不会执行以servers 文件夹(example.com/servers/foo, example.com/servers/foo/bar) 由example.com/servers/index.php 文件
如何编辑htaccess文件,以便所有请求example.com/servers/* 由执行example.com/servers/index.php 文件
SO网友:MrWhite
# Required when not in the webroot. Always use a trailing slash.
RewriteBase /
您的
RewriteBase / 指令导致所有请求(除了
/server/ 自身被重写回文档根目录。ie。
/index.php, 不
/server/index.php 如预期的那样。
旁白:我想补充一句,这条评论根本不是真的。这取决于你在做什么。事实上,通常情况下RewriteBase 应该完全省略指令(这里就是这种情况)。
(*1请求/server/ "E;“工作”;因为正则表达式. 在RewriteRule 指令失败,然后请求留给mod\\u dir发出内部子请求index.php - 这个DirectoryIndex - 在当前目录中。)
您需要:
移除此RewriteBase 指令-因为您正在重写index.php (相对路径)在当前目录中(默认行为)。
或,显式设置RewriteBase /server. (但这大部分是多余的。)