簡體   English   中英

Apache mod_rewrite:從url中僅刪除特定文件夾,並從該文件夾內的所有文件中刪除擴展名

[英]Apache mod_rewrite: remove only a specific folder from the url and remove the extension from all the files inside that folder

我嘗試了一些在Web上的.htaccess文件(位於網站根目錄中)上找到的其他解決方案,但最終總是遇到“內部服務器錯誤” ...

我需要一條通用規則,以從URL及其包含的所有文件的擴展名中刪除特定文件夾(在末尾添加斜杠),並重定向到重寫的url。 因此,例如:

我要處理的文件夾稱為“頁面”,因此該規則不應影響任何其他文件夾,並且我希望該網址

http://www.example.com/subfolder/pages/
will be rewrited/redirected to
http://www.example.com/subfolder/

http://www.example.com/subfolder/pages/page1.php
will be rewrited/redirected to
http://www.example.com/subfolder/page1/

http://www.example.com/subfolder/pages/subpages/page1.php
will be rewrited/redirected to
http://www.example.com/subfolder/subpages/page1/

等等...

我該如何實現?

在以下兩個規則中,這更合乎邏輯:

  1. 刪除擴展名:/subfolder/pages/(.*).[^.]+-> / subfolder / pages / $ 1 /
  2. 從URL刪除頁面:/subfolder/pages/(.*)-> / subfolder / $ 1

沒有測試規則,但這應該可以幫助您。

暫無
暫無

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

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