S
S
soofftt912015-04-05 00:43:16
htaccess
soofftt91, 2015-04-05 00:43:16

How to remove conflict in .htaccess?

Hello.
There is a site on which it was made that when opening any subdomain (sub.site.ru), content from the main domain (site.ru) was shown, and the subdomain itself (sub) was passed as a get parameter. There were no problems with this part, it was implemented like this:

# DirectoryIndex index.php
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+)\.site\.ru$ [NC]
RewriteRule ^(.*)$ index.php?sub_dom=%2 [L]

Then I needed to close all subdomains from indexing. To do this, I created two different files robot1.txt and robot2.txt. And I did a substitution with them from the standard "robots.txt" depending on the presence of a subdomain. If there is a subdomain, robot2.txt was opened, in which there was a ban on indexing. Made it with this code:
RewriteBase /
RewriteCond  %{HTTP_HOST} ([a-z0-9-]+).site.ru$
Rewriterule ^robots.txt$ /robots2.txt [L]

RewriteCond  %{HTTP_HOST} site.ru$
Rewriterule ^robots.txt$ /robots1.txt [L]

Separately, everything works as it should, but if you use these rules together, then the second does not work. And instead of "robots.txt" the index page opens.
I suppose that we need to make an exception to the first rule, but for a couple of hours I can’t figure out how to do it.
PS In addition to these two parts of the code, there is nothing else in .htaccess.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soofftt91, 2015-04-05
@soofftt91

Got it right after posting the question.

# DirectoryIndex index.php
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+)\.faberlicproject\.com$ [NC]
RewriteRule ^(.*)[^robots.txt]$ index.php?sub_dom=%2 [L]

# RewriteBase /
RewriteCond  %{HTTP_HOST} ([a-z0-9-]+).faberlicproject.com$
Rewriterule ^robots.txt$ /robots2.txt [L]

RewriteCond  %{HTTP_HOST} faberlicproject.com$
Rewriterule ^robots.txt$ /robots1.txt [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question