Roman
Roman

Reputation: 441

How to configure .htaccess for using Yii2 with Opencart in subfolder

I have an issue with proper configuration .htaccess file for Yii2 basic application.

I want to use Yii2 framework with Opencart store which a have installed to the /shop subfolder. According to Yii2 server setup guide, I need to set /web directory as a DocumentRoot. But then my /shop directory (which is located in a root of Yii2 installation) becomes non web-accessible.

So I decided to break the rules and set my Yii-root as DocumentRoot and redirect all of the requests to the /web dir with assistance of Apache's mod_rewrite.

Please help me to create valid .htaccess file for Yii-root folder (in Opencart folder I've put it's default .htaccess file with just changing RewriteBase to /shop. It seems work properly)

I need something like this:

Lets assume I set DocumentRoot /var/www, then:

http://sitename.com => /var/www/web/index.php
http://sitename.com/any-non-file-request => /var/www/web/index.php
http://sitename.com/favicon.ico => /var/www/web/favicon.ico

http://sitename.com/shop => /var/www/shop

Upvotes: 0

Views: 552

Answers (1)

Roman
Roman

Reputation: 441

Works now. .htaccess file in /var/www (root of Yii2 installation)

RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_URI} !^/web
RewriteRule ^(.*)$ web/$1 [QSA,L]

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

Upvotes: 1

Related Questions