简体   繁体   English

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

[英]subdomain wildcard .htaccess for escape cloudflare

I have example.com domain and set on cloudflare. 我有example.com域,并设置为cloudflare。 But some time I don't need to use cloudflare, so I create up.example.com subdomain and unused of cloudflare for it. 但是有一段时间我不需要使用cloudflare,因此我创建了up.example.com子域,并且没有使用它的cloudflare。 then I park it on main domain. 然后我将其停放在主域名上。 That means the example.com and up.example.com point to root site. 这意味着example.comup.example.com指向根站点。 Now for cover duplicate content in SEO, I need to a .htaccess file. 现在,对于SEO中重复的内容,我需要一个.htaccess文件。

These items is important for me: 这些项目对我很重要:

  • All URLs under main domain (example.com) must be open and accessible. 主域(example.com)下的所有URL必须是开放且可访问的。
  • The main page don't open with subdomain (up.example.com) and just open with main domain (example.com). 主页不以子域(up.example.com)打开,而仅以主域(example.com)打开。
  • All address with upload controller must be accessible from subdomain. 带有upload控制器的所有地址都必须可以从子域访问。 for example: up.example.com/upload/ 例如:up.example.com/upload/
  • The word after controller (my action) just is contain az, 0-9 (because don't allow use dot for point to a file) 控制器(我的动作)后的单词仅包含az,0-9(因为不允许使用点号指向文件)
  • About another URLs path must don't accessible from subdomain and must get 404 error. 关于另一个URL路径必须不能从子域访问,并且必须得到404错误。

For this, I write a code here: 为此,我在这里编写代码:

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]

But in this code my problem is: 但是在这段代码中,我的问题是:

  • up.example.com => open it! up.example.com =>打开它! but don't must open it. 但不必打开它。
  • up.example.com/upload/test => get me Not Found. The requested URL /index.php was not found on this server. 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. , but must open it. ,但必须将其打开。

Note: about another URLs I get correct 404 error, for example for up.example.com/upload/test.jpg I get Not Found. The requested URL /upload/test.jpg 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. error message, in this error message pointed exactly to /upload/test.jpg but about up.example.com/upload/test in error message pointed to index.php file! 错误消息,在此错误消息中完全指向/upload/test.jpg但在错误消息中指向up.example.com/upload/test指向index.php文件!

Please assist me to have correction .htaccess code. 请协助我获取更正的.htaccess代码。

I resolve this problem with help in this link . 我可以在此链接的帮助下解决此问题。
Just must use !^index\\.php$ instead . 只需使用!^index\\.php$ .

correction code: 更正代码:

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