dstudio
(Nedim T)
1
Hi everyone,
I’ve created an A record in DNS. This is how my path to the app looks like:
http://app.example.net
And something went wrong with links. Here’s how my frontend/config/main.php looks like:
'request' => [
'baseUrl' => '/',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'suffix' => '/',
'rules' => [
'' => 'site',
'logout' => 'site/logout',
]
],
This is how I format my links:
<a href="<?php echo Url::to(['user/index']); ?>">Users</a>
On my local machine everything is perfect, but on production, it’s not. I think it’s a problem because I use a subdomain.
Do you know what might be a problem?
Thanks
dstudio
(Nedim T)
2
Ok. I’ve found that the issue is related to rules.
When I add the next piece of code:
"http://app.example.com/<controller:\w+>/<action:\w+>" => '<controller>/<action>',
The problem is URL output is something like this:
http://app.example.com//site/about/
How can I remove one slash? Also,I haven’t tested with parameters.
hrnair
(Harikrishnan Hr)
3
to remove slash, change suffix.
dstudio
(Nedim T)
4
Hehe, not really. I’ve tried almost everything. It doesn’t work.
If I add ‘.html’ as a suffix my links will be as
http://app.example.com//site/login.html
Slash is still there. The suffix is actually about the last character(s).
Thanks anyway.
hrnair
(Harikrishnan Hr)
7
ok, with suffix you removed the last /.
Now, you can try using this much in your rules.
'<controller:\w+>/<action:\w+>" => '<controller>/<action>',
Still if you have problem, you can retain your rules and make baseUrl ‘’ instead of ‘/’.
dstudio
(Nedim T)
8
This rule does not work.
However, I’ve removed baseUrl but links now have /frontend/web/ which is not acceptable.
dstudio
(Nedim T)
9
Okay, I’ve found the solution – for those folks who host their app on the subdomain:
You need to have:
'request' => [
'baseUrl' => '',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'suffix' => '/',
'baseUrl' => '/',
],
Plus you need to have .htaccess in your /frontend/web/ (I had this before I’ve found the problem):
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
and in your root folder:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^admin/(.*)$ backend/web/$1 [L]
RewriteRule ^(.*)$ frontend/web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
# Upload limits
php_value post_max_size 100M
php_value upload_max_filesize 100M
Good luck to everyone!
jukilo123
(jukilo123)
10
Perfect!!! thanks a lot it works!!!