如何使用 apache mod_rewrite 重寫整個目錄?

如何使用 apache mod_rewrite 重寫整個目錄?

我需要這個 URL/目錄make/lores/some/來指向/映射到login/ 我還需要重寫.php擴展.html

例子

當客戶端在example.com/make/lores/some/login.html伺服器中鍵入時應該process example.com/login/login.php.

我有下面的規則,但問題是登入目錄下的其他文件(例如/login/images/one.png等)沒有被處理/重寫,所以我最終遇到了 404 錯誤。

RewriteRule     ^(.*)\.htm$     login/index.php [NC]

答案1

也許是這樣的:

RewriteEngine on
RewriteRule   ^/make/lores/some/(.+)  http://example.com/login/$1      [R,L]

這將處理對新 URL 的重寫。若要修正從.html到 的副檔名,.php您可以使用第二條規則:

RewriteRule   ^/login/(.+)\.htm$      http://example.com/login/$1.php  [R,L]

參考

相關內容