first question:
i already remove index.php
, but i want remove /web
also. this is my .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
and this is config/web.php
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
it's working fine, but it's still using /web
.
is it possible remove /web
?
second question:
i can't set route with parameter with that clean url, my route Url::toRoute(['transaction/getrequestdetail/', 'id' => 1 ]);
how the route should be ? and how with 2 parameter route ?
Using
str_replace('/frontend/web', '', (new Request)->getBaseUrl())
for detecting base URL is a bad idea and usingstr_replace('/web', '', (new Request)->getBaseUrl())
is a terrible idea.str_replace()
removes all occurences of requested string, sostr_replace('/frontend/web', '', (new Request)->getBaseUrl())
for URL/frontend/web/tools/frontend/webalizer
will give you/toolsalizer
. Definitely not a thing that you want.If you want to remove this string only from the begging of URL:
But the best solution would be avoiding the whole problem in the first place, for example by using symlinks to mimic required directory structure for single webroot.
You can add the information in file configuration to remove /web:
For advanced application follow these steps:
1) Add the following
htaccess
tofrontend/web
2) Add the following
htaccess
toroot folder
where application is installed3) Edit your
frontend/config/main.php
file with the following at the top4) Add the
request component
to the components array in the same file i.efrontend/config/main.php
That's it.Now you can access the frontend without web/index.php
For you second question you need to write the rule for it in your URL manager component.
Something like this:
If it still isn't working after going through the answers above, then you can edit your 'apache2.conf' file in your favorite editor to change
AllowOveride None to AllowOveride All
On Ubuntu, the file is located at /etc/apache2/apache2.conf
The final edit should look like
Finally, restart the Apache server