簡體   English   中英

子域通配符.htaccess用於逃生cloudflare

[英]subdomain wildcard .htaccess for escape cloudflare

我有example.com域,並設置為cloudflare。 但是有一段時間我不需要使用cloudflare,因此我創建了up.example.com子域,並且沒有使用它的cloudflare。 然后我將其停放在主域名上。 這意味着example.comup.example.com指向根站點。 現在,對於SEO中重復的內容,我需要一個.htaccess文件。

這些項目對我很重要:

  • 主域(example.com)下的所有URL必須是開放且可訪問的。
  • 主頁不以子域(up.example.com)打開,而僅以主域(example.com)打開。
  • 帶有upload控制器的所有地址都必須可以從子域訪問。 例如:up.example.com/upload/
  • 控制器(我的動作)后的單詞僅包含az,0-9(因為不允許使用點號指向文件)
  • 關於另一個URL路徑必須不能從子域訪問,並且必須得到404錯誤。

為此,我在這里編寫代碼:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^up\..+ [NC]
RewriteCond %{REQUEST_URI} !^(/upload/?[a-z,A-Z,0-9]*)$ [NC]
RewriteRule . - [R=404,L,NS]

# Hide index.php , this used for YII PHP Framework
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]

但是在這段代碼中,我的問題是:

  • up.example.com =>打開它! 但不必打開它。
  • up.example.com/upload/test =>讓我Not Found. The requested URL /index.php was not found on this server. Not Found. The requested URL /index.php was not found on this server. ,但必須將其打開。

注意:關於另一個URL,我得到正確的404錯誤,例如,對於up.example.com/upload/test.jpg,我Not Found. The requested URL /upload/test.jpg was not found on this server. Not Found. The requested URL /upload/test.jpg was not found on this server. 錯誤消息,在此錯誤消息中完全指向/upload/test.jpg但在錯誤消息中指向up.example.com/upload/test指向index.php文件!

請協助我獲取更正的.htaccess代碼。

我可以在此鏈接的幫助下解決此問題。
只需使用!^index\\.php$ .

更正代碼:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^up\. [NC]
RewriteCond %{THE_REQUEST} \s/+index\.php[?\s] [NC]
RewriteRule ^index\.php$ - [R=404,L,NC]

RewriteCond %{HTTP_HOST} ^up\. [NC]
RewriteCond %{REQUEST_URI} !^(/upload/?[a-z,A-Z,0-9]*)$ [NC]
RewriteRule !^index\.php$ - [R=404,L,NC]

# Hide index.php , this used for YII PHP Framework
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]

暫無
暫無

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

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