我正在嘗試使用.htaccess對一個檔案和檔案夾進行重定向。我想在RewriteRule之前添加一個RewriteCond指令,只匹配example.com/place/sta-ana.html和example.com/place/sta-ana目錄。我試著這樣做:
RewriteCond %{REQUEST_URI}。^place/sta-ana(.html|/.*)?
RewriteRule ^place/sta-ana(.html|/.*) ? /place/santa-ana$1 [L,NC,R=301]
還有這個:
RewriteCond %{THE_REQUEST}. ^place/sta-ana(.html|/.*)?
RewriteRule ^place/sta-ana(.html|/.*) ? /place/santa-ana$1 [L,NC,R=301]
但是這兩種方法只對重定向place/sta-ana.html起作用,而對目錄及其檔案如place/sta-ana/santiago.html和place/sta-ana/santiago/lourdes.html起作用。我怎樣才能讓上面的代碼也將sta-ana目錄重定向到santa-ana檔案夾:
example.com/place/sta-ana.html => example.com/place/santa-ana.html
example.com/place/sta-ana/santiago.html => example.com/place/santa-ana/santiago.html
example.com/place/sta-ana/santiago/lourdes.html => example.com/place/Santa-ana/santiago/lourdes.html
uj5u.com熱心網友回復:
看起來你不需要一個RewriteCond。只要這個規則就可以完成作業:
RewriteRule ^place/sta-ana(.html|/.*)$ /place/Santa-ana$1 [L,NC,R=301,NE]
確保這是你最重要的規則,在測驗這一變化之前,你必須完全清除你的瀏覽器快取。
。轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/309789.html
標籤:
上一篇:如何使用xpath獲得動態數字?
下一篇:如何用Sqlite制作多個資料庫
