I am using this code in my htaccess file to redirect all requests to index.php and it works.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
Now, I am trying to redirect few requests to another file public.php
(i..e load everthing via index.php if user is logged in, otherwise load files via public.php - that's the idea)
I have tried several methods which works for others but none of them seems to be working for me., I have no idea why.
the application structure is
[FOLDER]
app
www
static
.htaccess
And this is the .htaccess used in the root folder
RewriteCond %{HTTP_HOST} ^(www.)?website.com
RewriteRule ^(.*)$ www/index.php?$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^(static.)?website.com
RewriteRule ^(.*)$ static/index.php?$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^([^.]+)\.website\.com$ [NC]
RewriteRule ^(.*)$ app/index.php?$1 [L,QSA]
By default if the subdomain is www
or static
files are loaded from www
and static
folders respectively. If the url is accessed via some other subdomain then the files are loaded from app
directory.
The codes i tried are
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^public$ public.php [L,QSA]
RewriteRule ^(.*)$ index.php [L,QSA]
interchanged these two lines as well as tried with removing L, QSA
And many others.., As many i could find on Google + Stackoverflow., But none of them worked, I guess its not working due to how i have coded the .htaccess file in the root directory
.