我尝试过,我真的......我放弃。Wordpress和htaccess的...哦痛苦。
旧的静态网站有PDF,DOC,XLS和ZIP文件的所有根。 我已经加载的所有文件作为媒体项目,使他们都生活在/可湿性粉剂内容/上传。
我只是想捕捉任何404是.pdf文件重定向到文件夹上传。 应该很容易,但我显然不是做正确的事情。 htaccess具有SOOOO许多标志和设置的东西多来发生冲突或者我只是没有“得到它”。
RewriteEngine On
# Catch incorrect case (must be a better way of doing this?)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)\.JPG$ $1.jpg [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)\.PNG$ $1.png [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)\.GIF$ $1.gif [L,R=301]
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
# Start of my woes...what am I doing wrong?
RewriteCond %{REQUEST_FILENAME} .*\.pdf [NC]
#RewriteCond %{REQUEST_FILENAME} !\/wp-content\/uploads\/
RewriteRule ([^/]*\.pdf) /wp-content/uploads/$1 [NC,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^\/]*.zip) /wp-content/uploads/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^\/]*.xls) /wp-content/uploads/$1 [L,R=301]
# For bonus points, is this the correct way to do this? Catch old reference to an old folder and move them on?
RedirectMatch 301 /Graphic\sFiles/(.*\.jpg) /wp-content/uploads/$1
RedirectMatch 301 /Graphic\sFiles/(.*\.png) /wp-content/uploads/$1
RedirectMatch 301 /Graphic\sFiles/(.*\.gif) /wp-content/uploads/$1
我已经工作过:
- http://httpd.apache.org/docs/current/rewrite/flags.html
- http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
- http://httpd.apache.org/docs/current/rewrite/remapping.html#fallback-resource
SOOOO许多规则采取了我认为是一个简单的工作。 我没有htaccess的大师也绝不会,我有足够的尊重那些虽然!
感谢提前女士们,先生们任何指针。
皮特