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