I have a shared hosting on A2Hosting and I recently moved my main domain from public_html/
to public_html/subdir/
Here's the structure:
/public_html
/subdir(site files of main domain)
/api
index.php
My current htaccess(public_html) is :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.
RewriteRule ^(.*)$ /subdir/$1 [L]
When I called my APi before it was : domain.com/api/
But now it's : domain.com/subdir/api/
My htaccess in api
is :
RewriteEngine On
RewriteBase /api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
How to remove the "subdir" in the url to keep my api like previous ? But still point the root to my subdir with my current htaccess ?
Thanks
One way is to rewrite /api
from the main .htaccess file in the root directory like this:
RewriteEngine On
RewriteBase /
RewriteRule ^api/(.*)$ ../subdir/api/$1 [R,L,QSA]
The .htaccess file in the new /subdir/api folder can stays the way it is. Only the RewriteBase needs to be adjusted.
Another way is to rewrite from the previous /api
folder if you preserved it for some reason:
RewriteEngine On
RewriteBase /api
RewriteRule ^(.*)$ ../subdir/api/$1 [L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With