1

我有一个简单的 wordpress 页面,里面有一些新闻。在根目录中,我设置了带有规则的 .htaccess:

RewriteBase /news/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /news/index.php [L]

正如你所看到的,如果客户端请求一个不存在的文件或目录,他将被重定向到/news/index.php。

现在,我想设置,如果他从 /news/wp-content/uploads/ 子目录中调用不存在的图形文件,他应该得到一个自定义图形(比如说 /news/wp-content/uploads/noimage.png) . 为此我修改了.htaccess:

RewriteBase /news/wp-content/upload/
RewriteCond %{REQUEST_FILENAME !-f
RewriteRule . /news/wp-content/upload/notFound.png

RewriteBase /news/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /news/index.php [L]

但是现在当我尝试加载页面(甚至是索引页面)时,我得到了内部服务器错误。这里有什么问题?

4

2 回答 2

1

您的第一条规则实际上是劫持所有合法的 WP 请求,因为这些请求永远不会用于有效文件。用这个替换你的完整代码:

如果 wp-contnent 目录中没有 .htaccess:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /news/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(wp-content/uploads)/.+$ $1/notFound.png [L,NC]

RewriteRule ^index\.php$ - [L]

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

如果 wp-contnent 目录中有 .htaccess,则在文件顶部使用此代码wp-contnent/.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^uploads/.+$ /news/wp-content/uploads/notFound.png [L,NC]
于 2013-09-26T12:34:55.313 回答
0

与其摆弄 RewriteBase,不如试试这个:

RewriteCond %{REQUEST_URI} ^/news/wp-content/upload/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /news/wp-content/upload/notFound.png [L]
于 2013-09-26T12:35:35.513 回答