目录的404特定图像错误(符号链接)

时间:2013-12-08 02:41:07

标签: wordpress .htaccess mod-rewrite http-status-code-404

我正在尝试提供依赖于目录的特定jpeg图片。

例如:

  • /i/t/150/63211.jpg => /i/404/150.jpg
  • /i/t/195/63211.jpg => /i/404/195.jpg

目前,即使是简单的事情(一次一条规则),例如:

RewriteCond %{REQUEST_URI} ^/i/t/150/.*\.jpg
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^.*$ /i/404/150.jpg  [L]

即使我的jpeg文件位于目录/ i / 404 /.

中也不起作用

我认为问题来自/ i /是符号链接的事实。

我的目标是在同一个RewriteRule中使用2条规则(适用于150.jpg / 195.jpg)。但是,让我们试着让它只与一个人合作。

这是我完整的htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^(.*)-a([0-9]+)\.html$ 301oldninapeople.php?oldid=$2&section=news [L]
RewriteRule ^(.*)-n([0-9]+)\.html$ 301oldninapeople.php?oldid=$2&section=theme [L]
RewriteRule ^(.*)-n([0-9]+)-page([0-9]+)\.htm$ 301oldninapeople.php?oldid=$2&section=theme [L]

RewriteRule ^301oldninapeople\.php$ - [PT,L]

RewriteCond %{REQUEST_URI} ^/i/t/150/.*\.jpg
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^.*$ /i/404/150.jpg  [L]



RedirectMatch 301 ^/rss/news.(xml|asp)$ /feed

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# 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

第一个回答后的当前robots.txt:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^i/t/([^/]+)/.+?\.jpg$ /i/404/$1.jpg [L,NC,R]

RewriteRule ^(.*)-a([0-9]+)\.html$ 301oldninapeople.php?oldid=$2&section=news [L]
RewriteRule ^(.*)-n([0-9]+)\.html$ 301oldninapeople.php?oldid=$2&section=theme [L]
RewriteRule ^(.*)-n([0-9]+)-page([0-9]+)\.htm$ 301oldninapeople.php?oldid=$2&section=theme [L]

RewriteRule ^301oldninapeople\.php$ - [PT,L]




RedirectMatch 301 ^/rss/news.(xml|asp)$ /feed
# RedirectMatch 301 ^/rss/news.xml$ /feed
# RedirectMatch 301 ^/rss/news.asp$ /feed

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# 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

1 个答案:

答案 0 :(得分:0)

您只需要这条规则:

RewriteCond %{DOCUMENT_ROOT}/$0 -f
RewriteRule ^i/t/([^/]+)/.+?\.jpg$ /i/404/$1.jpg [L,NC]

另请确保将此规则作为第一条规则移至RewriteBase /行下方。