![](/img/trans.png)
[英].htaccess rewrite in subdirectory not working under root directory with .htaccess
[英]Rewrite first level subdirectory to root directory passing folder name .htaccess
我有一個應用程序,我在其中傳遞客戶名稱以確定要在頁面上顯示哪些信息。
以前我將它設置為基於子域,例如https://client1.company.com
、 https://client2.company.com
。 我會解析子域以確定客戶名稱,並且每個子域都指向服務器上的同一組文件。
我必須將其更改為基於子目錄,因此現在將是https://company.com/client1/
、 https://company.com/client2/
等。
是否有一個 .htaccess 重寫規則可以用來基本上將帶有子目錄的任何請求重寫回根目錄? 這樣,當 ajax 請求從https://company.com/client2/
發送到服務器時,它會將請求重定向到https://company.com/ajax.php
,而不是將請求發送到https://company.com/client2/ajax.php
並且沒有找到。
當加載樣式表等時,它會將https://company.com/client1/assets/css/style.css
重定向到https://company.com/assets/css/style.css
。
您可以在站點根目錄 .htaccess 中使用此規則:
RewriteEngine On
# redirection to a level up
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[\w-]+(/.*)$ $1 [L,R=301]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.