簡體   English   中英

使用.htaccess文件隱藏和重命名文件夾

[英]hide and rename a folder using .htaccess file

假設我的網站上有一個鏈接,如下所示: www.example.com/test/index.php 我想對訪問者隱藏“測試”文件夾,並使其顯示為“蘋果”,以便當用戶鍵入www.example.com/applewww.example.com/apple/index.php ,它自動重定向到www.example.com/test/index.php 我想通過如下編輯.htaccess文件來使其成為可能:

RewriteEngine On
RewriteRule ^test/(.*) apple/$1

但是,它不起作用。 這里有什么問題嗎? 如何重命名文件夾?

對於PHP文件:

例子1

RewriteRule ^/?api/([^/]+)?$ "request.php?rquest=$1" [L,QSA]

例子2

RewriteRule ^/?api/([^/]+)/([^/]+)?$ "request.php?rquest=$2&ns=$1" [L,QSA]

其中request.php是文件。 將被稱為example.com/api/{ns}/{rquest}在后者和example.com/api/{rquest}在前。

如果要使用文件夾,請按照以下要求使用。 請測試一下,因為我還沒有使用過。

RewriteEngine on
RewriteBase /
RewriteRule ^/?apple/([^/]+)?$ "test/index.php?categories=$1" [L,QSA]

這只是一個重寫規則。 您定義一個模式,然后將其與要重寫的模式進行匹配。 就那么簡單。

您是否要忽略后面的斜線? 那就像

應該將example.com/help/legal/privacy/eula改寫為example.com/help.php?path=/legal/privacy/eula ,然后您必須忽略URL模式中帶help的路徑中的/

您可以像下面這樣簡單地更改正則表達式:

RewriteRule ^/?help/(.+)?$ "help.php?topic=$1" [L,QSA]

因此,正則表達式使用(.+)表示,采取並采取一切措施,不要停止。

因此,這是URL語法:

RewriteRule {regex_of_url_pattern} "{rewrite_into_what}" [OPTIONS ...]


有關更多信息和示例,請參閱

暫無
暫無

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

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