V
V
Vladimir2017-07-31 11:22:45
Yii
Vladimir, 2017-07-31 11:22:45

Why in yii2 when urlManager enablePrettyUrl is enabled, the page display is not correct?

Good day! I installed clean yii2 2.0.12 and the start page is displayed like this:
582ecc81fff54ba4a9edb4d2e0cc3387.png
This is after I registered the Apache config (The site is on the local OpenServer server):

#-----------------------------------------------#
# Начало блока конфигурации HTTP хоста
#-----------------------------------------------#

<VirtualHost *:%httpport%>

    DocumentRoot    "%hostdir%/web"
    ServerName      "%host%"
    ServerAlias     "%host%" %aliases%
    ScriptAlias     /cgi-bin/ "%hostdir%/cgi-bin/"

</VirtualHost>

#-----------------------------------------------#
# Конец блока конфигурации HTTP хоста
#-----------------------------------------------#

There I highlighted the main points. And when I enable it in yii config
'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
    ],
],

becomes like this:
4ff808a4166b430f9175aaf8043f5cb8.png
When created htaccess with these parameters:
Options +FollowSymLinks
IndexIgnore */*

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

Everything fell into place as in the first picture, but when you go to other links, it gives an Internal Server Error
Internal Server Error solved the issue by simply putting htaccess in the wrong place. Moved htaccess to web folder and links started working

Tell me what I did wrong? And how, for example, to be if on Shared hosting where there is no access to Apache configs and you cannot change the DocumentRoot there, but only create your own htaccess. I understand that you can create a ticket and ask to do it for me, but I'm wondering if the approach is possible without changing the DocumentRoot.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-07-31
@MasterGerold

It is easiest to change the structure to shared. Move everything from the web to the root of the public folder, and throw everything else into the yii folder, for example, one level higher than the public folder and correct the paths in index.php
Here is a video with the structure for shared hosting:
https://youtu.be/hg5t5F3HdM4?list= PLOm4dl-NavgyBnt...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question