-2

我在 htaccess 中有以下代码。

# BEGIN Wordpress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]

# Add this line
RewriteCond %{REQUEST_URI}    !/document         [NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]

# Add these lines
RewriteCond %{REQUEST_URI}  !search\.php         [NC]
RewriteCond %{REQUEST_URI}  /document/([^/]+)/?  [NC]
RewriteRule .*  /wordpress/search.php?id=%1      [L,NC]

</IfModule>
# END Wordpress

#Add this/these line(s) 下的行是我的自定义代码,用于将任何 URL 重定向http://example.com/document/123http://example.com/search.php?id=123.

现在我想修改此代码以避免在更新/安装 WordPress/插件后我的自定义规则被 WordPress 覆盖。

我怎样才能做到这一点?

4

1 回答 1

2

只需将您的第二个附加块移动到 WordPress 部分之前。重写规则中的[L]标志应防止评估任何剩余的条件和规则。您不需要添加的第一行。

# Your additions
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI}  !search\.php         [NC]
RewriteCond %{REQUEST_URI}  /document/([^/]+)/?  [NC]
RewriteRule .*  /wordpress/search.php?id=%1      [L,NC]
</IfModule>

# BEGIN Wordpress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]

</IfModule>
# END Wordpress
于 2013-04-09T16:25:01.980 回答