O
O
OccamaRazor2016-12-11 15:18:13
Yii
OccamaRazor, 2016-12-11 15:18:13

How to set normal URLs in .php files of a Yii project?

server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
If you think this is a server error, please contact the webmaster.
error 500

<IfModule mod_autoindex.c>
      Options -Indexes
</IfModule>
    
<IfModule mod_rewrite.c>
    Options +FollowSymlink
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /web/index.php
</IfModule>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-12-11
@slo_nik

Good afternoon.
What exactly do you want to do?
Remove "web" from address bar?
If so, then it's done a little differently.
You need two .htaccess
The first one should be put in the "web" directory

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#RewriteCond %{REQUEST_URI} ^/web/*
RewriteRule . index.php

Second to the root of the site, on the same level as "web"
<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine on
</IfModule>

<IfModule mod_rewrite.c>
   RewriteCond %{REQUEST_URI} ^/.*
   RewriteRule ^(.*)$ web/$1 [L]

   RewriteCond %{REQUEST_URI} !^/web/
   RewriteCond %{REQUEST_FILENAME} !-f [OR]
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^.*$ web/index.php

</IfModule>

Now the address for the index page will be site.com , not site.com/web
ps And to configure the so-called routing, configure the rules in the configuration file for UrlManager
ps All .htaccess will work with yii2-basic if you need to configure for yii2 -advanced, then there will be other rules
return [
  'components' =>[
     'urlManager' => [
        // настройки urlManager
     ]
  ]
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question