How to send all request to index.html - reactjs - javascript

I'm using linux OS and apache.
I created a webapp directory inside public_html. inside public_html I have a landing page. I want to keep this landing page.
all resources can fetch as well.
but I got Page not found error.
I found out that I should send all requests to index.html file.
.htaccess file:
<ifModule mod_rewrite.c>
#######################################################################
# GENERAL #
#######################################################################
# Make apache follow sym links to files
Options +FollowSymLinks
# If somebody opens a folder, hide all files from the resulting folder list
IndexIgnore */*
#######################################################################
# REWRITING #
#######################################################################
# Enable rewriting
RewriteEngine On
# If its not HTTPS
RewriteCond %{HTTPS} off
# Comment out the RewriteCond above, and uncomment the RewriteCond below if you're using a load balancer (e.g. CloudFlare) for SSL
# RewriteCond %{HTTP:X-Forwarded-Proto} !https
# Redirect to the same URL with https://, ignoring all further rules if this one is in effect
RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R,L]
# If we get to here, it means we are on https://
# If the file with the specified name in the browser doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f
# and the directory with the specified name in the browser doesn't exist
RewriteCond %{REQUEST_FILENAME} !-d
# and we are not opening the root already (otherwise we get a redirect loop)
RewriteCond %{REQUEST_FILENAME} !\/$
# Rewrite all requests to the root
RewriteRule ^(.*) /
</ifModule>
<IfModule mod_headers.c>
# Do not cache sw.js, required for offline-first updates.
<FilesMatch "sw\.js$">
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
</IfModule>
but I got not found message error:
https://parsebar.com/webapp/login

I use this snippet in my .htaccess when my react app runs in a subfolder:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

Related

Laravel 8 and running on the server

I have a problem with running Laravel 8 on the production server.
In the root directory I put the .httpacces file from the public directory and changed the name of the server.php file to index.php
Everything works except styles, js, and more
The contents of the .httpacces file
Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
What do I have to change, add? Thank you very much for the hint.
You do not want to rename the server.php. Whether you are using Apache or nginx, make sure your Documents Root points to the public!! folder of your Laravel application. Never point it to the main directory. You can find configurations for nginx and apache online regarding laravel.

.htaccess blocks images from mobile site aka root/mobile

I been researching countless topics regarding accessing images when a user is logged into a mobile site. I'll try to explain everything to the point and any help is super appreciated.
I have website (root/index.html) and a mobile version redirected to (root/mobile/index.html) via .htaccess
I have all my subscribers individual folder accounts as followed: (root/1234567, root/1122334, root/9876543, etc..) with their uploaded images inside (root/1234567/image1.png, etc...)
When a user logs into mobile via (root/mobile/login.php) and tries to view an image via JavaScript www.mysite.com/1234567/image1.png it "breaks".
I tried all suggestions in my research, however when I delete .htaccess from root it works so I know the root .htaccess file is the culprit but I do need security on subscribers folders (root/1234567 etc...) but allow access on image files within subsribers folders. I can post both .htaccess files contents of root and root/mobile
Here's my root .htaccess file
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_USER_AGENT}
"android|blackberry|iphone|ipod|ipad|iemobile|opera
mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^((?!mobile/).*)$ /mobile [L,R=301]
<FilesMatch "\.(htaccess|htpasswd|ini|log|sh|inc|bak|txt)$">
Order Allow,Deny
Deny from all
</FilesMatch>
ErrorDocument 403 https://www.mysupersite.com/
ErrorDocument 404 https://www.mysupersite.com/
Options -Indexes
And my root/mobile .htaccess file
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.mysupersite.com/mobile [L,R=301]
RewriteCond %{HTTP_USER_AGENT}
"!android|blackberry|iphone|ipod|ipad|iemobile|opera
mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^ https://www.mysupersite.com [L,R=301]
<FilesMatch "\.(htaccess|htpasswd|ini|log|sh|inc|bak|txt)$">
Order Allow,Deny
Deny from all
</FilesMatch>
ErrorDocument 403 https://www.mysupersite.com/mobile
ErrorDocument 404 https://www.mysupersite.com/mobile
Options -Indexes

How to fix .js file url redirect to double WWW?

When i try to access the resource on the browser like below
Before
It automaticly Became like this and causing error
After
It is working fine without www. but i need to load the web with www.
Any advice?
Here is my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
It is working fine too for images and css files.. but not for js files
Css Example
Image Example
UPDATE
looks like the problem only occured on a js file that has more than 1 dot..
for example https://www.testweb.com/js/bootstrap.js has 1 dot in bootstrap.js and it's working fine
but https://www.testweb.com/js/bootstrap.min.js has 2 dots.. and it caused double www
Any Clue?

.htaccess causes fail in parsing source maps

On the web page the .htaccess is:
RewriteEngine On
RewriteBase /
Options -MultiViews
DirectorySlash Off
# skip POST requests
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
# redirect to .php-less link if requested directly
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.php $1 [R=301,L]
Options All -Indexes
ErrorDocument 403 /img/error.php
ErrorDocument 404 /img/error.php
ErrorDocument 500 /img/500.png
It causes the next error:
Failed to parse SourceMap: .../js/bootstrap-select.js.map
When I delete it, the error doesn't occur.
How should I modify .htaccess?
Even though you had answered yourself just i want to post this so that others with this issue will know exactly what that happens
Warning:
Do not use .htaccess to redirect error to another HTML/PHP page or server
that isn't your own (such as this error.php). Errors can be replaced
by other images, not with an HTML or PHP page as that might cause indefinite
loop too.
Solved the problem by changing error.php to a picture ( in error.php there was redirect to index page ).

Basic Apache rewrite rules for enabling HTML 5 state links in an AngularJS app with ui-router

I have my web application structured as follows -
http://integration.web-url.com/app1
and
http://integration.web-url.com/app2
My application is an angularJS application that has html 5 state links enabled. I've followed the pattern explained here -
AngularJS: can't get html5 mode urls with ui-route $state
as follows
<IfModule mod_rewrite.c>
RewriteEngine on
<Directory "${POTD}/htdocs">
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^(.*)app1(.*) app1/index.html [L]
RewriteRule ^(.*)app2(.*) app2/index.html [L]
</Directory>
</IfModule>
But I get a 404 error when attempting to goto any url other than app1/index.html or app2/index.html

Categories