[英]subdomain wildcard .htaccess for escape cloudflare
我有example.com
域,並設置為cloudflare。 但是有一段時間我不需要使用cloudflare,因此我創建了up.example.com
子域,並且沒有使用它的cloudflare。 然后我將其停放在主域名上。 這意味着example.com
和up.example.com
指向根站點。 現在,對於SEO中重復的內容,我需要一個.htaccess
文件。
這些項目對我很重要:
upload
控制器的所有地址都必須可以從子域訪問。 例如:up.example.com/upload/ 為此,我在這里編寫代碼:
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]
但是在這段代碼中,我的問題是:
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.