我需要在wordpress在.htaccess文件中生成的行之间动态添加几行。
这是.htaccess文件在wordpress生成时的样子:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress我想在RewriteRule ^index.php$ -L之间添加我的行
和
RewriteCond %{REQUEST_FILENAME} !-f
如下所示:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# BEGIN THIS DL-FILE.PHP ADDITION
RewriteCond %{REQUEST_URI} ^.*content/uploads/PROTECTEDFOLDER/.*
RewriteRule ^wp-content/uploads/(PROTECTEDFOLDER/.*)$ wordpress/dl-file.php?file=$1 [QSA,L]
# END THIS DL-FILE.PHP ADDITION
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress我尝试使用mod_rewrite_rules filter来添加行,但只在wordpress生成的行的上方和下方添加了行。
发布于 2015-01-05 06:18:17
您是否可以使用Generate Rewrite Rules操作打开.htaccess文件并插入额外的内容?
http://codex.wordpress.org/Plugin_API/Action_Reference/generate_rewrite_rules
下面是一些伪代码:
// On the generate_rewrite_rules hook...
// Grab the htaccess file
$htaccess = file_get_contents(get_home_path() . '.htaccess');
// find where you want to insert
$character_position = strpos($htaccess, "RewriteCond %{REQUEST_FILENAME} !-f");
$new_htaccess = substr_replace($htaccess, "#BEGIN ...", $character_position, 0);
// Save the file... etc这可能有点麻烦,但在我看来,这比参与实际的内置重写函数要好得多。
https://stackoverflow.com/questions/27770831
复制相似问题