Reputation: 35
let me get to the point.
I have a php project that has this structure
ROOT
.htaccess
--api/
----public/
------index.php
------test.html
--backoffice/
And what I want is to use the index.php of api/public to get it working like
domain.com/api/index.php
instead of
domain.com/api/public/index.php
I've been trying with no success the rewritebase or rewriterules of .htaccess, I'm missing something? putting the .htaccess in the wrong directory? I have to use multiple .htaccess?
UPDATED: So I got my two .htaccess files, by now I'm able to access with the url domain.com/api/index.php but it throws 401 , it's something... on the other hand I can access to the file test.html located under /api/public with the current url domain.com/api/test.html
Here are the .htaccess
domain.com/api/ .htaccess file
RewriteEngine On
RewriteBase /api/public/
RewriteCond %{REQUEST_URI} !^/api/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /api/public/$1
domain.com/api/public/ .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
Upvotes: 0
Views: 115
Reputation: 566
I think you can use a seperate .htaccess
file in your API folder
with a rule like this:
RewriteRule ^$ /public [R=301,L]
So this should redirect internally to the subfolder public
ROOT
| --api/
| |-- .htaccess
| |-- public/
| |-- index.php
|-- backoffice/
Update1
I think in your case this should work
RewriteEngine On
RewriteBase /api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ /api/public/$1 [L]
It depends also on the System which you are using and the preset.
Update2
I did some test on XAMPP an got to following result
Put your .htaccess
in the ROOT folder
,
delete
all other .htaccess files in subfolders
.
Rename api
to _api
or something, as you like
ROOT
| --.htaccess
| --/_api/ <<<------- rename
| |-- /public/
| |-- index.php
|-- /backoffice/
add this .htaccess
to root
RewriteEngine On
Options FollowSymLinks
RewriteBase /
DirectoryIndex index.php index.html
RewriteRule ^api2/(.*)$ /api/public/$1 [B,L,QSA]
Call as before yoursite.com/api
This scenario worked on my test system as expected. Give it a try.
Upvotes: 2