5

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

Efbi
  • 412
  • 2
  • 10
  • 34
  • I think you can change the basePath in the apache config easily – zedling May 30 '18 at 08:42
  • Hi @zedling , sorry I forgot to mention that I'm on shared hosting – Efbi May 30 '18 at 10:08
  • I hope you did not move application files under public html – Zamrony P. Juhara May 31 '18 at 01:08
  • Hi @ZamronyP.Juhara, which application files you means ? All my files are on the subdir – Efbi May 31 '18 at 11:44
  • What version of slim are you using here? Can you show your index.php code? – anubhava Jun 04 '18 at 17:58
  • @Efbi - do you have a dedicated FQDN to this site? if you do, you could use VirtualHost with the same config you had, just point to a different DocumentRoot, you don't have to mess around the existing rewrite rules. Let me know I can provide you a config example. – runwuf Jun 06 '18 at 15:54

1 Answers1

4

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]
wp78de
  • 16,078
  • 6
  • 34
  • 56