Unable to access subroutes and home page in yarn build React app - html

I'm trying to deploy a React app to the public site and everything works ok on localhost. When I put the website up and go to the url (i.e. www.something.com), the home page renders fine including static assets.
Then, when I created an .htaccess file containing:
FallbackResource /
The subroutes all render fine (static assets incl js, css, images), but the home page errors with a 502 Bad Gateway.
However, when I go to a subroute (i.e. www.something.com/about), it 404s.
I built using yarn build
I'm using "react-router-dom": "^5.1.2"
I set up the app using create-react-app
package.json contains "homepage": "."
What am I doing wrong here?

This question ended up being answered by .htaccess rewrite to redirect root URL to subdirectory
I redirected to the homepage as in the example and kept my FallbackResource defined.
RewriteEngine On
RewriteRule ^$ /index.html [L]
FallbackResource /index.html
I noticed you can also use any other defined route here (i.e. /contact)

Related

Deployed laravel app, only homepage working

I have recently finished a website for a customer, the site works great locally. Currently only the homepage is working. However all links return a 500 server error.
This is 1and1, and I haven't heard many good things about it.
Currently I have the laravel folders for my app within a folder called webapp.
the domain name points to webapp/public.
I have also added the following line to my htaccess to get it to work
RewriteRule ^ /home.php [L]
which works for the homepage. I don't know much about the htaccess file, so I've messed around with a few other options such as
RewriteRule ^ /folios.php [L]
as well which is one of the links in my site, however this doesn't work.
My routes currently work like this
Route::get('/folios', 'AlbumsController#index');
However they return 500 server error
Change the line in the ".htaccess" file in the root folder from RewriteRule ^ index.php [L] to
RewriteRule ^ /index.php [L]
My suspicion is that you need to update the paths contained within public/index.php
Check out this article for instructions: https://medium.com/#Bohr/deploy-laravel-application-on-shared-hosting-godaddy-953758dc57ac
Did you run composer install on the server or copy out the vendor directory? You may also want to check that your htaccess file in the public directory contains the directives that are required (https://github.com/laravel/laravel/blob/master/public/.htaccess).
I did not realize that the server generated a new .htaccess file within the /webapp/ folder where I pointed the domain; I was editing the wrong .htaccess file

"public_html" automatically appearing after folder name in URL and resulting in 404

I was fiddling around with the .htaccess in my web hosting directory, attempting to force HTTPS to my URLs to activate my SSL that comes with Hostgator (which did in fact work), but after changing stuff in there and whenever I try to access my page by simply typing in the URL bar examp.com the browser automatically adds public_html after it, which results in a 404, and only when I remove the public_html part of the URL am I able to access the HTML documents and folders. But if I type https://www.exampe.com THEN it works properly without adding anything. I was unable to find anything regarding this problem and it happens with every browser.
My .htaccess file looks like this:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1
Even after removing it the problem persists.
EDIT: The foulder structure is home3/example/.htaccess
EDIT: I should probably mention this, when I originally edited the .htacces file in the first place it was not present, literally nowhere in my hosting directory on Hostgator, not even after checking "Show dotted files", so I ended up creating it manually and then I started fiddling with the code above.

Web Pages Ending with ..../

I have a website running without a domain name (it is connected to using my public IP) on Apache. I have several pages (eg. /Chemistry/) and the default page is index.html so when MYIP/Chemistry/ is typed in, it goes to MYIP/Chemistry/index.html.
This is fine and all but I was wondering why sites like https://stackoverflow.com/questions don't need a / at the end. If I did MYIP/Chemistry it wouldn't work, but for sites like stackoverflow, they don't need a forward slash. So my question is why is this and how can I make it this way for my website? Thanks!
You could achieve the same result by using rewriteUrl module in apache, it allows you to manipulate (rewrite) URLs :
First, you have to activate mod_rewrite:
sudo a2enmod rewrite
Setting Up .htaccess file
create .htacces in route directory of your site
sudo nano /var/www/html/.htaccess
and then add your rewrite rules and save:
RewriteEngine on
RewriteRule ^(.*)/+$ $1 [R=301,L]
the above rule will remove all slashes from the end of any url

Chrome won't display filesystem images

Problem: When I try to load the image as part of the web page, I get (blocked:other) as a response to the image request in the Chrome inspector (as opposed to 200 or 404). When I paste the image location into the address bar, it loads, so I know the path is correct. Same responses from Firefox.
Example path that loads directly in browser but not in web page/css: file:///Users/my-username/path-to-app/assets/images/give-them-beer/12-top-rated-ipas_1200.jpg
Example path that doesn't load anywhere (returns 404 in inspector): http://localhost/mysite.com/assets/images/give-them-beer/12-top-rated-ipas_1200.jpg
System info:
I'm working on a localhost website (Mac, using MAMP + Apache).
I'm using the latest version of Chrome.
Web site info:
I am using CodeIgniter 3.x
My assets directory is outside the application directory
I am using the full filesystem path for the image.
I am loading images as CSS background using inline styles
What I've investigated:
I've tried localhost URLs and filesystem URLs
.htaccess CSP options, though I can't find one that fixes the problem
.htaccess XSS options, but again, I can't figure out how to get around it
The MAMP permissions suggestions the comments. New permissions are:
Localhost dir: drwxr-x---+ 7 ME _www 238 Sep 10 09:37 DOCUMENTDIRECTORY
Website dir: drwxrwx---+ 15 ME _www 510 Sep 11 09:50 MYSITEDIRECTORY
You could try switching the setting in MAMP "Run Apache/MySQL server as user:" to run as your local user account rather than "www", if you haven't already.
It turned out it to a CodeIgniter configuration issue. I needed to add the assets folder to the .htaccess rewrite rules, like this:
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|resources|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Redirecting nonexistent index.html to home page in Wordpress is causing too many redirects in browser

I recently changed my website from static html to Wordpress, and in doing so I've been redirecting all of my former and nonexistent pages with my .htaccess file whenever Google shows me a crawl error. I've been successful in redirecting all crawl errors until today. My old index.html is throwing a crawl error and when I use:
Redirect 301 /index.html http://www.example.com
... I get this from my browser:
Too many redirects occurred trying to open www.example.com. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.*
I have since removed the above redirect from my .htaccess file and will just live with the crawl error if I can't get this resolved. But I'm thinking somebody knows how to solve this and if so, I'd really appreciate it if you'd let me know how.
You could experience this redirect loop if your DirectoryIndex is set to index.html (as the first option), which is likely to be the default setting on your server.
Basically, when you access a directory, eg. http://example.com/ (the root directory) then the DirectoryIndex directive tells the server which file to serve (via an internal rewrite). eg. http://example.com/index.html. This then seeds the redirect loop.
Since you are using WordPress, you could change this in .htaccess to favour index.php instead. For example, at the top of your .htaccess file:
DirectoryIndex index.php index.html
However, you could also solve this by using mod_rewrite (which is probably preferable). In fact, since WordPress already uses mod_rewrite (eg. RewriteRule directive) then you should also be using mod_rewrite for your redirects, not mod_alias (eg. Redirect directive). You should not mix redirects from both modules in .htaccess since you can easily get conflicts. Different modules execute at different times, regardless of their order in .htaccess.
By using mod_rewrite you can avoid a redirect loop by checking against THE_REQUEST. For example:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html [NC]
RewriteRule ^index\.html$ / [R=301,L]