Yang
Yang

Reputation: 8701

Cannot properly merge two .htaccess

There are 2 .htaccess files, one in / and the second in /web folders.

In a root folder (/), .htaccess looks like

RewriteEngine on
RewriteRule    ^$ web/    [L]
RewriteRule    (.*) web/$1 [L]

In /web folder, .htaccess looks like

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

It works perfectly.

All I want is to merge those conditions and put them inside a single .htaccess that would be in root directory (/).

1 - I've tried to add RewriteBase, like

RewriteBase /web

2 - I've tried to replace conditions that aware of web folder

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

3 - I've tried to simply append a config from one file to another with slight alterations.

But none of this works - It gives internal 500 server error.

How a proper merging should be done in this case?

Upvotes: 0

Views: 39

Answers (2)

zessx
zessx

Reputation: 68790

This .htaccess (in the root folder) should match to your needs :

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

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

Upvotes: 2

Jon Lin
Jon Lin

Reputation: 143896

If you're putting all the rules in your document root (/) then try:

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

Upvotes: 1

Related Questions