I simply want to access the backend part via www.domain.com\admin
and frontend by www.domain.com
. What I did in my root .htaccess
is :
Options -Indexes
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/admin/$
RewriteRule ^(admin)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]
RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1
It redirects to the the frontend but doesn't work properly with the backend. Can't realize what is the problem because I am using the same lines of configurations at work and there everything is OK. Can it be because of the XAMPP
? We work on Ubuntu
and Apache
server at my workplace. This is the frontend and backend ( they are similar ) also :
AddDefaultCharset utf-8
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# Make the backend accessible via url: http://site/admin
RewriteRule ^admin$ $admin.php [L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
RewriteRule ^static - [L]
EDIT: I DID IT!
What I was set in my httpd-vhost.conf
was :
<VirtualHost *:8080>
ServerName fitness
DocumentRoot "c:/xampp/htdocs/fitness/frontend/web"
</VirtualHost>
And the problem was that I was redirecting my request to the frontend/web
htaccess
but what I really needed was the root .htaccess
. So I had changed the DocumentRoot
to c:/xampp/htdocs/fitness
.
I always use the following way when setting up a new project when I am working in the office where we have
ubuntu
and it always works perfectly.Follow these steps below, and create 2 virtual hosts with the name
www.myapp.com
andadmin.myapp.com
1) Open terminal and type
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/www.myapp.com.conf
.sudo nano /etc/apache2/sites-available/www.myapp.com.conf
.add the following code once the file opens.
2) Close & save the file and then in terminal write
sudo a2ensite www.myapp.com.conf
sudo nano /etc/hosts
and add in the end on a new line127.0.0.1 www.myapp.com
.sudo service apache2 restart
3) Repeat the above steps for the
backend
and change the file names andServerName
,Directory
andDirectoryRoot
respectively.4) Just make sure you have a
.htaccess
file in thefrontend/web
andbackend/web
with the followingAnd thats it you wont need any other
.htaccess
file other than these now type in the browserwww.myapp.com
oradmin.myapp.com
and see it working.