How to display robots.txt file - problem with htaccess

Hi, I am using Yii2 advanced.

Root structure:

public_html

>frontend

-web


....

>backend

....

htaccess in public_html:


AddHandler application/x-httpd-php54 php

Options -Indexes


<IfModule mod_rewrite.c> 

  RewriteEngine on


  RewriteCond %{REQUEST_URI} !^public 

  RewriteRule ^(.*)$ frontend/web/index.php/$1 [L]


RewriteCond %{REQUEST_FILENAME} robots.txt$ [NC]

RewriteRule ^([^/]+) $1 [L] 

</IfModule>


# Deny accessing below extensions

<Files ~ "(.json|.lock|.git)">

Order allow,deny

Deny from all

</Files>


# Deny accessing dot files

RewriteRule (^\.|/\.) - [F]

And in frontend/web:


RewriteEngine on


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d 


RewriteRule . index.php



I need to use the file robots.txt, but when I type the address: http://mydomain.com/robots.txt I have an error 404.

What should I change/add in htaccess file?

Is your robots.txt sitting in public_html?

This might work, but when it comes to the black magic of .htaccess, I’m really only guessing…




<IfModule mod_rewrite.c> 

  RewriteEngine on


  RewriteCond %{REQUEST_URI} !^public 

  RewriteCond %{REQUEST_FILENAME} !-f

  RewriteRule ^(.*)$ frontend/web/index.php/$1 [L]

</IfModule>



Ok, it works!

How can I set the htcaccess file to go mydomain.com/admin and this will reredirect to backend/web ?

create folder "admin" in web root

add file .htaccess


<IfModule mod_rewrite.c>

we check if the .html version is here (caching)

RewriteRule ^$ index.html [QSA]

RewriteRule ^([^.]+)$ $1.html [QSA]

RewriteCond %{REQUEST_FILENAME} !-f

no, so we redirect to our front web controller

RewriteRule ^(.*)$ ../backend.php [QSA,L]

</IfModule>

we check if the .html version is here (caching)

RewriteRule ^$ index.html [QSA]

RewriteRule ^([^.]+)$ $1.html [QSA]

RewriteCond %{REQUEST_FILENAME} !-f

no, so we redirect to our front web controller

RewriteRule ^(.*)$ ../backend.php [QSA,L]


add rule for backend in config of backend

‘urlManager’ => array(

                'urlFormat' =&gt; 'path',


                'showScriptName' =&gt; false,


                'urlSuffix' =&gt; '.html',


                'rules' =&gt; array(


                    '' =&gt; 'admin/site/dashboard',


                    'admin' =&gt; 'process/login',


                    'admin/&lt;_c&gt;' =&gt; '&lt;_c&gt;',


                    'admin/&lt;_c&gt;/&lt;_a&gt;' =&gt; '&lt;_c&gt;/&lt;_a&gt;',


                ),


            ),