【问题标题】:subdomain wildcard .htaccess for escape cloudflare用于逃逸 cloudflare 的子域通配符 .htaccess
【发布时间】:2014-10-15 13:27:38
【问题描述】:

我有 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/
  • 控制器(我的操作)之后的单词只是包含 a-z、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.,但必须打开它。

注意:关于另一个 URL,我得到了正确的 404 错误,例如 up.example.com/upload/test.jpg 我得到了 Not Found. The requested URL /upload/test.jpg was not found on this server. 错误消息,在这个错误消息中正好指向 /upload/test.jpg 但关于 @987654331错误消息中的@ 指向index.php 文件!

请协助我更正.htaccess代码。

【问题讨论】:

  • 这个问题仍未得到解答的原因是一个问题中包含了太多的要求。尝试简化它。

标签: apache .htaccess subdomain wildcard cloudflare


【解决方案1】:

我在this link 的帮助下解决了这个问题。
只是必须使用!^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]

【讨论】:

    猜你喜欢
    • 2014-04-01
    • 2015-06-10
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 2014-09-06
    • 2012-01-23
    • 2011-06-05
    • 1970-01-01
    相关资源
    最近更新 更多