重写规则 deppend 表单请求域



我有一个存储库用于 2 个实例代码:domain.comapi.domain.com .

规则应该是什么样子的:

api.doamin.com域提供另一个robots.txt文件

对于域api.domain.com,阻止除api.domain.com/api/以外的流量(/api/允许,/resources/,...不允许或重定向到主域(

编辑 1:(建议更改后 .htaccess(

# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
Redirect "/f/" "/assets/"
# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>
RewriteCond %{HTTP_HOST} =api.domain.com
RewriteRule !^api/ [F,NC]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule .(gif|jpe?g|png|bmp)$ index.php/image404/index/?r=%{REQUEST_URI} [NC,L]
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

>robots.txt并没有真正阻止所有Web请求,它只是指示爬虫不要爬过某些路径。

最好像这样对这种阻止使用mod_rewrite规则:

RewriteEngine On
RewriteCond %{HTTP_HOST} =api.doamin.com
RewriteCond %{THE_REQUEST} !s/+api/ [NC]
RewriteRule ^ - [F]

此规则将阻止api.doamin.com不会/api/路径的域的所有流量。

请注意,这也将为http://api.domain.com/提供 403。

如果需要独立于重写的其他设置,请使用:

SetEnvIf HOST ^api.domain.com$  API_SITE
AddType application/x-httpd-php70 .php ENV=API_SITE

为了在robots.txt中为域api单独的指令,请将此规则放在RewriteEngine On行的正下方:

RewriteCond %{HTTP_HOST} =api.doamin.com
RewriteRule ^robots.txt$ /robots-api.txt [L,NC]

这将重写对/robots.txt的请求,以便为apirobots-api.txt

现在使用以下内容创建一个名为 robots-api.txt 的新文件:

Disallow: /

最新更新