我的網址:
www.example.com/about/about_me.html
我想讓它看起來像這樣,并打開about_me.html檔案
www.example.com/about
我想搜索我的域名,后面是/about,打開的頁面是about_me.html。我想用我的htacess檔案做到這一點。還有一件事,就是我把我的.htacess檔案放在我的服務器上的位置
。uj5u.com熱心網友回復:
這變得更加復雜,因為/about映射到檔案系統上的一個物理目錄。通常情況下,mod_dir會添加尾部的斜線(301重定向),以 "修復 "URL。為了防止這種情況,我們需要禁用這種行為,然而,這樣做有潛在的注意事項和安全問題。如果這被禁用,你可能需要在系統的其他地方手動覆寫它。
在根檔案.htaccess中嘗試以下做法:
# Disable directory listings (mod_autoindex)
選項 -Indexes
# 防止mod_dir附加尾部的斜線
關閉DirectorySlash
# 啟用重寫引擎(mod_rewrite)
重寫引擎開啟
# 內部重寫"/about "為"/about/about_me.html"
RewriteRule ^about$ about/about_me.html [L] 。
現在,對/about的請求將提供/about/about_me.html。但是請求 /about/ (帶有尾部斜線) 將導致 403 Forbidden (假設在 /about 子目錄中沒有DirectoryIndex 檔案)。
而請求任何其他沒有尾部斜線的目錄(例如:/subdirectory)也將導致403禁止,無論該目錄中是否有DiretcoryIndex檔案存在。
mod_autoindex需要被禁用(即Options -Indexes),以防止在DirectorySlash Off被設定時意外的資訊泄露。請參閱有關DirectorySlash的Apache手冊頁面。https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryslash
為了使生活更容易,避免使用直接映射到檔案系統目錄的URL(沒有尾部斜線)。例如,您可以將所有的內容存盤在一個
/content子目錄中,然后將/about URL映射到/content/about/about_me.html。那么你就不需要禁用DirectorySlash(而且如果你需要的話,阻止對/content的直接訪問也是很容易的)。
例如:
# Enable the rewrite engine (mod_rewrite)
重寫引擎開啟
# 內部重寫"/about "為"/content/about/about_me.html"
RewriteRule ^about$ content/about/about_me.html [L] 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/328150.html
標籤:
上一篇:遷移學習神經網路不是學習
