我有一個目錄,就像www.example.com/comments/a/word1.html我洗掉的comments/a/部分和.html鏈接中的 htaccess 一樣。在a檔案夾下我有很多檔案,如 word1.html、word2.html、word3.html,我想像這樣重定向所有這些檔案:
www.example.com/word1
www.example.com/word2
www.example.com/word3
我正在使用這個 .htaccess 代碼:
RewriteEngine on
RewriteRule ^/?comments/a/(.*)(/|\.html)?$ /$1 [R=301,L]
RequestCond %{DOCUMENT_ROOT}/comments/a%{REQUEST_URI}.html -f
RewriteRule ^/?(.*)/? /comments/a/$1.html [END]
但我收到錯誤“找不到 404 頁面,在此服務器上找不到請求的資源!”。在這種情況下我能做什么?有沒有辦法將www.example.com/comments/a/word1.html word2-3-4 等重定向到www.example.com/word1
uj5u.com熱心網友回復:
由于我的研究,我找到了這樣的解決方案:
##Rewrite non /comments/a/ links internally start##
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/comments/a/$1.html -f
RewriteRule ^/?([^.?] )$/?$ comments/a/$1.html [L,NC]
##Rewrite non /comments/a/ links internally end##
這段代碼對我來說就像一個魅力。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/440154.html
