rasny92
(Saminiemi)
1
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?
patrickm
(Yiiframework)
2
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>
rasny92
(Saminiemi)
3
Ok, it works!
How can I set the htcaccess file to go mydomain.com/admin and this will reredirect to backend/web ?
huunguyen
(Nguyen Huu Nguyen)
4
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' => 'path',
'showScriptName' => false,
'urlSuffix' => '.html',
'rules' => array(
'' => 'admin/site/dashboard',
'admin' => 'process/login',
'admin/<_c>' => '<_c>',
'admin/<_c>/<_a>' => '<_c>/<_a>',
),
),