L
L
lsa4132015-11-20 10:49:16
Yii
lsa413, 2015-11-20 10:49:16

How to generate CNC in yii2 without web/ in address bar?

Hello!
I'm trying to get rid of the web folder in the address bar in the yii2 project and following links.
I'll write down the steps, what I did and what doesn't work:
To begin with, I'll clarify that the basic distribution kit is in the localhost folder, and basic has been renamed to the site name. In short, in the browser the site is accessed like this:
localhost/sitename/web
What I did:
1. In the web folder I created .htaccess with the content (taken from the yii documentation):

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

2. In the config/web.php file I include urlManager in the components section:
'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],

Now the CNC is working and you can easily set up all sorts of templates, but you need to get rid of the web/ folder in the browser address bar. And this does not work in any way.
Let me explain that I want to do this without editing the VirtualHost in Apache, preferably only using .htaccess and Yii2 settings.
There are several tips on the net about this topic, but none of them worked for me. Obviously, you need to create an .htaccess at the root of the site and configure it to strip web/ from the request and pass it to .htaccess in the web folder. This variant of .htaccess roams the net, but I repeat, it does not work for me :
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule (.*) /web/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php

It is also advised to set an empty baseUrl in config/web, but then in general all paths collapse, especially for included js and css scripts.
What to do? :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2015-11-20
@R0dger

If your APACHE looks into the localhost folder, then rebuild it so that it looks directly into the WEB folder and you will be happy ..

A
A1eksandr, 2015-11-20
@A1eksandr

1)
htaccess in WEB folder.
# Mod_Autoindex
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)?$ index.php
In config:
'request' => [
'baseUrl' => ''
],
possibly you will need to reconfigure the routes depending on what is now written
2) The second option, you can specify in the virtual host settings apache DocumentRoot /web/ then you don’t need to do anything else

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question