Link to home
Start Free TrialLog in
Avatar of stargateatlantis
stargateatlantis

asked on

.htaccess directory issue

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.
Avatar of Kenza Cohen
Kenza Cohen
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of stargateatlantis
stargateatlantis

ASKER

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
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.
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.
So what would be best so that nothing gets cached. You can include that in the .htaccess as well
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

ASKER CERTIFIED SOLUTION
Avatar of Kenza Cohen
Kenza Cohen
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
RewriteRule ^spa/img/(.*)$ /spa/dist/img/$1 [R=302,NC,L]
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
No Problem,
Please select the solutions that helped so that the question can be closed.

Kenza