htaccess -子目錄中的.htaccess 不繼承根目錄中的.htaccess

htaccess -子目錄中的.htaccess 不繼承根目錄中的.htaccess

我有 2 個 .htaccess 文件

首先在/public_html/

#ErrorDocument 404 https://example.com/en/404.php
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/ws/
RewriteCond %{REQUEST_URI} !/en/
RewriteCond %{REQUEST_URI} !/ar/
RewriteCond %{QUERY_STRING} !lang=en
RewriteCond %{QUERY_STRING} !lang=ar
RewriteRule (.*) $1?lang=en [QSA]

另一個檔案位於 /public_html/jobs/

RewriteOptions inherit
DirectoryIndex index.php
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} ((\d+)?)
RewriteRule ((\d+).*?)  /job/index.php?JobID=$2 [QSA]

我想重定向 URL:

https://example.com/jobs/123

到:

https://example.com/job/index.php?JobID=123&lang=en

但結果是

https://example.com/job/?JobID=1196147

沒有 lang 參數

我不知道為什麼它不起作用,我需要兩個文件中的規則,因為根文件中有許多其他規則

謝謝。

答案1

我剛剛遇到了同樣的問題 - 我通過使用RewriteOptions InheritBefore而不是僅僅RewriteOptions Inherit在子目錄中的文件之前處理父目錄中的 .htaccess 文件來解決它

相關內容