.htaccess directory issue

stargateatlantis
stargateatlantis used Ask the Experts™
on
Struggling with this in a .htaccess file

the root folder has the following folders

/myweb
  /api
  /spa

in the spa folder there is a folder called /dist
and in the api folder there is a folder called /api/public/

when somebody types mydomain.com/ it will access the /spa/dist folder and access all the assets under so the page displays
when somebody access the /api folder it will access the /api/public folder

but no redirects it will be rewrites.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kenza CohenIT Solutions Provider

Commented:
Try the following:

RewriteEngine on
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /spa/dist/$1 [L]
RewriteRule ^api/(.*)$ /api/public/$1 [R=301,NC,L]

Open in new window


You may have a problem with the API folder though

Author

Commented:
That worked but here is a issue.

the source code points to the following css path /css/styles.css  but the file doesn't exist another rewrite needs to be done so that anything with the following will be pointing to the dist folder

images | css | js

so so everything works now just we need the images css and js folder to be rewritten in apache
Kenza CohenIT Solutions Provider

Commented:
Try

RewriteRule ^(.*\.(gif|jpg|png))$ /spa/dist/$1 [QSA,L]
RewriteRule ^(.*\.(js))$ /spa/dist/$1 [QSA,L]
RewriteRule ^(.*\.(css))$ /spa/dist/$1 [QSA,L]

Open in new window


If they are linked as in a folder you could try:

RewriteRule ^images/(.*)$ /spa/dist/$1 [R=301,NC,L]
RewriteRule ^css/(.*)$ /spa/dist/$1 [R=301,NC,L]
RewriteRule ^js/(.*)$ /spa/dist/$1 [R=301,NC,L]

Open in new window


If not if the website is internet facing if you could give me a link to see how it is displaying or paste the source code.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

David FavorFractional CTO
Distinguished Expert 2018

Commented:
1) Tip: Only use 302s. If you use 301s, then you'll end up with links cached in your browser forever. This means no changes you make will register in your browser, till you clear your cache.

2) For mydomain.com to reach /myweb/spa/dist the simple solution is to make the the document root, so no .htaccess entry.

3) Place files in /api/public/* folder into /myweb/spa/dist/api to serve those files.

Seems like you're making this overly complex.

If I understand your question correctly, there's no requirement for any .htaccess rules, just a simple directory hierarchy.

4) Mentioning styles.css suggests you may be working with a WordPress site, so best describe the code you're working with.

For example, custom code or some CMS code like WordPress, as this will limit or change any type of .htaccess contents you use.

Author

Commented:
So what would be best so that nothing gets cached. You can include that in the .htaccess as well

Author

Commented:
Here is the issue

this code here

Its linked like this in code.

<link href=/js/app.d44788ce.js rel=preload as=script>

Open in new window


the file doesn't exist but it exists in  spa/dist/js/app.d44788ce.js

this code doesn't work

RewriteRule ^images/(.*)$ /spa/dist/$1 [R=301,NC,L]
RewriteRule ^css/(.*)$ /spa/dist/$1 [R=301,NC,L]
RewriteRule ^js/(.*)$ /spa/dist/$1 [R=301,NC,L]

Open in new window


Or this

RewriteRule ^(.*\.(gif|jpg|png))$ /spa/dist/$1 [QSA,L]
RewriteRule ^(.*\.(js))$ /spa/dist/$1 [QSA,L]
RewriteRule ^(.*\.(css))$ /spa/dist/$1 [QSA,L]

Open in new window

IT Solutions Provider
Commented:
RewriteRule ^js/(.*)$ /spa/dist/js/$1 [R=302,NC,L]

Open in new window


remove:
RewriteRule ^(.*\.(gif|jpg|png))$ /spa/dist/$1 [QSA,L]
RewriteRule ^(.*\.(js))$ /spa/dist/$1 [QSA,L]
RewriteRule ^(.*\.(css))$ /spa/dist/$1 [QSA,L]

Open in new window

Author

Commented:
That sorta of worked but if you go here

/spa/dist/img/logo.82b9c7a5.png

The image will show up but what I need is

/spa/img/logo.82b9c7a5.png

should be able to do that without the redirect
Kenza CohenIT Solutions Provider

Commented:
RewriteRule ^spa/img/(.*)$ /spa/dist/img/$1 [R=302,NC,L]

Author

Commented:
I tried that doesn't work here is the code

RewriteEngine on
RewriteCond %{HTTP_HOST} lamc\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /spa/dist/$1 [L]

RewriteRule ^api/(.*)$ /api/public/$1 [R=302,NC,L]
RewriteRule ^spa/img/(.*)$ /spa/dist/img/$1 [R=302,NC,L]
RewriteRule ^spa/js/(.*)$ /spa/dist/js/$1 [R=302,NC,L]
RewriteRule ^spa/css/(.*)$ /spa/dist/css/$1 [R=302,NC,L]

Open in new window


I get 404 errors
So I got it working thanks for your help.  There could be some tweaks made to it

RewriteEngine On
RewriteCond %{HTTP_HOST} lamc\.com [NC]

RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /spa/dist/$1 [L]
RewriteRule ^api/(.*)$ api/public/$1 [L]
RewriteRule ^img/(.*)$ spa/dist/img/$1 [L]
RewriteRule ^js/(.*)$ spa/dist/js/$1 [L]
RewriteRule ^css/(.*)$ spa/dist/css/$1 [L]

Open in new window

David FavorFractional CTO
Distinguished Expert 2018

Commented:
If I understand, you're trying to...

1) Arrange your assets (files) across some directories.

2) Then reference these assets by a different path.

3) With no redirects.

Likely answer will be to just use symlinks on the disk.

This means your .htaccess file will be empty.
Kenza CohenIT Solutions Provider

Commented:
No Problem,
Please select the solutions that helped so that the question can be closed.

Kenza

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial