簡體   English   中英

Apache RewriteRule 重寫子目錄不起作用

[英]Apache RewriteRule to rewrite subdirectories not working

我需要重寫以下 URL 結構:

http://website.com/business-directory/25/administration/

到:

http://website.com/departments/administration/

我添加了這個 RewriteCond 和 RewriteRule 但我無法讓它工作。

RewriteCond %{HTTP_HOST} website.com
RewriteRule ^business-directory/.*/(.*)/$ /departments/$1/

我一直在使用此在線工具進行測試,並獲得了成功的結果。 但我不知道他們在驗證規則的工具背后的邏輯。

https://htaccess.madewithlove.be?share=11bb2f4c-7d70-5ee9-9551-2d81d5a5d340

我還是 Linux 和 Apache 的新手,所以我的故障排除技能有限。 我嘗試使用此命令搜索 error_log 文件並使用 grep 管道傳輸所有重寫條目,但沒有日志條目。 當我點擊應該重寫的 URL 時,我正在實時查看日志。

tail -f error_log|fgrep '[rewrite:'

這直接來自 Apache 用戶手冊。

我正在運行的堆棧是 Bitnami Wordpress Multisite。

你實際上有幾個問題。 看起來您想將business-directory/NN/name/departments/name/ 正如我所說,您需要在部門名稱后加一個斜杠。 這很好,但它只會重寫與business-directory/NN/name/的完全匹配,並且會因business-directory/NN/name/whosdead.html 如果要轉換所有 URL,則需要捕獲部門名稱的任何蹤跡:

RewriteRule ^business-directory/.*?/(.*?)(/.+?)?$ /departments/$1$2

http://website.com/business-directory/62/coroner轉換為http://website.com/departments/coroner

http://website.com/business-directory/62/coroner/轉換為http://website.com/departments/coroner/

http://website.com/business-directory/62/coroner/whosdead.html轉換為http://website.com/departments/coroner/whosdead.html

一旦你確認重寫引擎實際上正在處理你的規則,試試這個 RewriteCond 看看它是否工作得更好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM