Question

Changing the root folder via .htaccess

Hello , I’m using Apache with yii2 and i have 2 route /en , /ar i want app by default open to /ar

Options -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [R=301,L]
</IfModule>

RewriteEngine on
#RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^128.199.50.203$
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [R=301,L]


# Preventing Redirect loop
RewriteRule ^(frontend|backend)/web/ - [L]
RewriteRule ^(common)/web/ - [L]

RewriteCond %{REQUEST_URI} !^/api
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_URI} !^/app
RewriteCond %{REQUEST_URI} !^/backend
RewriteCond %{REQUEST_URI} !^/uploads

RewriteRule ^(.*)$ /frontend/web/index.php/$1 [L]

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

Doing this via the .htaccess might be a bit tricky, instead I believe that this extension would work for you:

https://github.com/codemix/yii2-localeurls

It is quite flexible and configurable, you could specify the following scenario:

/ar
/ar/some/page
/               -> Redirect to /ar
/some/page      -> Redirect to /ar/some/page

Regards, Bobby