我的站點位于,https://itjmovies.com/milan/public/我想通過.htaccess檔案重寫 URL 。從https://itjmovies.com/milan/public/到https://itjmovies.com/milan/但它不起作用。還有https://itjmovies.com/milan/public/auth/index.php?page=newTohttps://itjmovies.com/milan/public/auth/new/但這也不起作用。
我已經保存了我的.httaccess檔案/www/wwwroot/itjmovies.com/milan/.htaccess
我的.htaccess檔案:
RewriteEngine On
RewriteRule ^/(.*)$ /public/$1 [R=301,NC,L]
RewriteRule ^public/auth/([a-zA-Z] ) /index.php?page=$1 [QSA,L]
謝謝你 :)
uj5u.com熱心網友回復:
我不確定您的編輯是否使您的問題更清楚。在您的問題描述中,所述的重寫(從/到)似乎與我認為它們的意圖是錯誤的(并且與您撰寫指令的順序沖突),但無論如何......
我的假設:
/public不應該是可見 URL 的一部分。盡管您的站點位于/milan/public目錄中。您正在通過表格提出請求/milan/<anything>。- 您需要在內部重寫來自
/milan/<anything>/to 的所有請求/milan/public/<anything>。 - 表單的請求
/milan/public/auth/<something>/(注意尾部斜杠,如您的示例中所述)應在內部重寫為/milan/public/auth/index.php?page=<something>
我會有 2 個.htaccess檔案。/milan子目錄中的一個,它只是將請求重寫/轉發到public子目錄。另一個.htaccess檔案/milan/public處理特定于您的應用程式的重寫。
例如:
# /milan/.htaccess
RewriteEngine On
# Forward all requests to the "public" subdirectory
RewriteRule (.*) public/$1 [L]
# /milan/public/.htaccess
RewriteEngine On
# Rewrite "auth/<something>/" to "auth/index.php?page=<something>"
RewriteRule ^auth/([^/] )/$ auth/index.php?page=$1 [QSA,L]
當請求被父目錄中的檔案重寫到子目錄時,.htaccess檔案 at/milan/public/.htaccess還用于防止重寫回圈。這是因為默認情況下不繼承 mod_rewrite 指令。public.htaccess
QSA僅當您期望原始請求中的查詢字串時才需要該標志。
該RewriteRule 模式(第一個引數)的URL路徑相對于包含的目錄相匹配.htaccess的檔案。
RewriteRule ^/(.*)$ /public/$1 [R=301,NC,L] RewriteRule ^public/auth/([a-zA-Z] ) /index.php?page=$1 [QSA,L]
關于您的嘗試的一些說明 - 很接近,但有一些嚴重的錯誤:
- 由匹配的URL路徑
RewriteRule模式不以斜線(在使用時開始.htaccess),所以正則運算式^/(.*)$將不會匹配。 - 第一條規則也是外部重定向(即暴露
/public子目錄),這似乎不正確。難道你真的想/public在可見URL -如果是這樣,那么你應該直接鏈接到/public子目錄,而不是依靠一個重定向? - 第一條規則是重定向到
/public檔案根目錄,而不是/milan/public. - 一旦更正,第一條規則也將導致重寫回圈(500內部服務器錯誤),因為它會反復重寫請求......
public/public/public/<something>等。 - 第二條規則也是
/index.php在檔案根目錄中重寫,而不是/milan/public/auth/index.php.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/344856.html
