Answer the question
In order to leave comments, you need to log in
Yii2 404 error when removing /web from url on localhost using .htaccess?
Hello. The problem is this: using .htaccess I want to make the url display host/site/index instead of host/web/site /index . There is already a topic on how to do this, here How to remove web/ from url in Yii2 basic using .htaccess and urlManager rules? However, when I create .htaccess I put in there:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule ^assets/(.*)$ /web/assets/$1 [L]
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule (.*) /web/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php
Answer the question
In order to leave comments, you need to log in
Good morning.
I do through two .htaccess
First, in web/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
<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>
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rule' => [
'' => 'site/index',
'<_a:[\w-]+>' => 'site/<_a> // для остальных страниц по умолчанию, about, contact
]
]
Do you have 1 url or do you need a regular expression to remove all web from the url?
If you need to do this for the entire site
THEN there are already more options, the simplest thing is just to do a "soft link" and that's it, then the site will physically lie there and there. But most likely it won't work.
if you need regular
RewriteCond %{REQUEST_URI} ^/dir1/(.*)$
# если строка начинается с /dir1/
RewriteRule ^(.*)$ /dir1%1 [R=301,L]
#Перенаправить все урлы с начинающиеся с dir1 на dir2 с сохранением дальнейшей структуры URL
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question