Refreshing page shows file not found error - angularjs

I am using apache server for an angularJS web-app. Its purely based on AngularJS/HTML5 and has no server side programming like php or others.
When I say localhost on my browser (Chrome 49+), it takes me to http://localhost/Login/Index as per the routes defined. But when I refresh the page, browser says The requested URL /Login/Index was not found on this server.
I went through some posts on stackoverflow and tried this in my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
Options FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]
</IfModule>
I tried removing few lines and it shows me some error while refreshing the page. So this means that .htaccess file is being applied. So I suppose the problem must be with the RewriteRule. What should I write in the RewriteRule? Any other quick/better way to solve this problem?

Related

Error message when navigating through react website after uploading it on bluehost

Full error message: Not Found
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
My problem is when I uploaded my build file to cpanel(via bluehost) I started getting this error when I try to navigate to different pages within my react. The homepage works and displays all that it's supposed to. My local host doesn't have this problem because according the react documents the development server knows how to handle the requests. I have researched everywhere on the internet for the answer to this problem, but nothing seems to work.
This is the configuration in my .htaccess file in my public directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
This is my package. json file:
My build file was uploaded as a zip file into cpanel > public_html. All files were extracted from the build folder and moved into public_html. Like previously stated my homepage works but when I navigate to other pages it does not.
npm run build without a .htaccess file
In cpanel in the top right corner there is a settings option. Choose settings and check the option "show hidden files." (also make sure you're in the document root)
In the top left corner there is the option to add a file. Click that and create a new .htaccess file.
Paste this in the new file, save it and you should be able to move through your website without the error message. Hopefully I just saved you the 5 days it took me to figure this out.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

React Route: 404 Not Found after refreshing the deployed application

I'm working for a company and just deployed a project for them, but I encountered an issue. so, when you go to the link http://domain, you can go to the page, and from there you can go to any other page (react route), but if you go directly to http://domain/some-end-point, it shows 404 not found. does anyone know how to fix it?
That happened because your server side doesn't handle redirect to index.html, You can fix it by config your back end to always redirect to html, or simply you can fix it from react-router using HashRouter instead of BrowserRouter
here is a full explanation about Server side vs client side routing
Add the following code to the public folder file name should be
_redirects
/* /index.html 200
refer image
You can fix this with .htaccess in the root folder :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>

.htaccess 500 internal server error when routing api

I'm currently running php on an apache server locally, with a React frontend.
This is how my current .htaccess is laid out:
Options -MultiViews
RewriteEngine On
RewriteRule ^api/(.*)$ api/$1\.php [L]
RewriteCond %{REQUEST_URI} !^/api.*?
RewriteRule ^ index.html [QSA,L]
The bottom condition is so that routing works in my React app. I'm then taking the production build and copying it into my htdocs.
The routing works, however, I want to be able to call the .php files inside my /api directory without using the file extension. So I want anything that comes after /api/ to be redirected to whatever is entered, followed by .php.
E.g. /api/authentication would go to /api/authentication.php, and /api/register would go to /api/register.php, and so on.
With this current setup, I'm getting a 500 internal server error when making requests to /api/authentication etc.
Is there something wrong with my .htaccess file?
Your first rule is looping as you're matching .*. You may use:
Options -MultiViews
RewriteEngine On
RewriteRule ^index\.html$ - [L,NC]
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteRule ^api/(.+)$ api/$1.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^api index.html [L,NC]
RewriteCond %{REQUEST_URI} !\.php$ [NC] will skip rewriting when a URI ends with .php.

my WordPress 404 Not Found error had been gone :)

I used WordPress for the first time and I changed the URL settings and this error appeared
The requested URL /index.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
I tried to find .htaccess file but there's no such file and I tried to create one but the error still appears
I really don't know what to do .. any help, please?
-EDIT: I solved the Error
https://www.youtube.com/watch?v=vgyaK7dpJB0&t=0s&list=LLDSGkl9MD0q2BjLLJ82nAmA&index=5
this youtuber saved my life
You need to add .htaccess file. and add the code below in .htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

My css file is requiring /index.php as part of the url

Ive taken a copy of expressionengine from our production server to a dev server and its installed and running. I can access the admin console fine and Ive updated my paths.
The problem is that when I try and view my site the main page loads but no CSS is downloaded. The error Im getting is
The requested URL /presentation/layout was not found on this server.
I cant access the file from http://localhost/presentation/layout but I can access from
http://localhost/index.php/presentation/layout
Ive updated my .htaccess file from the following guide
https://docs.expressionengine.com/latest/urls/remove_index.php.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
I can access the site now from http://localhost without the index.php but its still looking for it for the CSS file. Any idea how I can resolve this?
First thing: don't put your css file in a template unless you absolutely have to.
You only need dynamical css files if the styles are depending on the data in a channel like
{exp:channel:entries}
.{title} {
color: #{color_custom_field};
}
{/exp:channel:entries}
If you put it in a template it will be processed by the template parser on every page view. This will add extra queries/processing which isn't needed for a static file.
What version of EE are you on?
All of us EE guys are over at https://expressionengine.stackexchange.com/ by the way

Resources