Skip to content

Instantly share code, notes, and snippets.

@Vermorr
Last active July 16, 2017 20:47
Show Gist options
  • Save Vermorr/dc46750dc8b40af262d33647ad1d040a to your computer and use it in GitHub Desktop.
Save Vermorr/dc46750dc8b40af262d33647ad1d040a to your computer and use it in GitHub Desktop.
.htaccess main
Это требуется, если у нас yii2 находится в подкаталоге, и не хочется нарушать структуру проекта
BasicApp ( root ) > .htaccess
RewriteEngine On
RewriteRule ^$ web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ web/$1
Однако, чтобы не были видны файлы типа yii.bat и прочие, нужно убрать вот эти строки:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
То есть сделать просто:
RewriteEngine On
RewriteRule ^$ web/
RewriteRule ^(.*)$ web/$1
Так мы все запросы переадресуем на web/$1
BasicApp ( root ) > web > .htaccess
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
in config
'urlManager' => [
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
]
Взял [отсюда] (http://www.codematrics.com/htaccess-in-yii2-basic-app/)
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'fdvo540fk4ZPiNFfmIu8Kc-v3HuHIb_R',
'baseUrl' => '',
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment