2
我试过了,我真的有...我放弃了。WordPress和htaccess ...哦,痛苦。移动pdf文件的htaccess规则?
旧的静态网站在根目录中有pdf,doc,xls和zip文件。我已将所有文件加载为媒体项目,因此它们都位于/ wp-content/uploads中。
我只是想抓住任何404这是一个.pdf文件,并将其重定向到上传文件夹。应该很容易,但我显然没有做正确的事情。 htaccess拥有许多标志和设置,以至于有些事情会发生冲突,或者我只是没有“获得它”。
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大师,永远不会,我对那些虽然是很尊重!
感谢提前女士和男士的任何指针。
皮特
没有。不怕。就像你的逻辑一样,我尝试了一些类似的东西,但它根本没有选择它,只是显示一个404页面。 – 2012-08-02 11:49:27
@PeteDuncanson我刚刚意识到一些事情,如果你将这些规则移到WordPress规则之上,它是否工作? – 2012-08-02 11:54:40
宾果!将wordpress规则移到底部,并将其排序:) – 2012-08-02 12:47:53