on refreshing page , not found error, need solution without using # [duplicate] - angular9

This question already has an answer here:
Cannot load routing modules after building in Angular
(1 answer)
Closed 2 years ago.
I have a angular 9 project. I deployed it to server. On server when I refresh angular app, it shows error :
Error:
start
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.
end
we are using below for development
server : Apache
frontend : angular
backend : nodejs
I did not understand what happened. I tried this solution
link to solution what I found
but We don't want # in over url. with out #, we want solution.
please suggest proper solution.
thanks for your time.

Build your app like this using angular cli.
ng build --prod --base-href /<project_name>/
Try with this in .htaccess one and let me know as It works for me.
Put .htaccess in src folder (final path for is src/.htaccess) and give the file path in angular.json inside "assets"
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Reference

You need to place a .htaccess file on the root of the deployed project i.e. along with index.html. Below is the code to be written in the above file.
<IfModule mod_rewrite.c>
RewriteEngine on
# 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 ^ index.html [L]
Please see the below image -

Related

Image url being treated as a page request in yii2

I am working on a project which is developed in Yii2. Today I came across a weird and funny issue of image url being treated as a page request.
When I try accessing image with url as https://www.websitename.com/images/image1.jpg, it shows me the image. And when I try accessing image with url as https://www.websitename.com/images/image1-lockdown.jpg then it shows 404 Error. On checking I found that internally the request was changed to "/site/images/image1.jpg". As we all know to access images no controller call is made.
Same issue was generated on local machine (Ubuntu 16.04). Just added "lockdown" into the name of image url.
I am using Yii2 Advanced Template. OS: For production CentOS and for development Ubuntu 16.04.
Note: I couldn't verify if the same issue exists for windows or not.
Kindly Help!
Edited: .htacess (root folder on production)
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule admin(.+)?$ /backend/web/$1 [L,PT]
RewriteRule gamer/(.+)?$ /gamer/web/$1 [L,PT]
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ /frontend/web/$1 [L]
</IfModule>
.htaccess (frontend/web on production)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

Yii2 The requested page does not exist **Not Found (#404)**

I'm new to Yii2,
here is the website almousa.net
the issue here that I can not go to the backend, I always get The requested page does not exist and the page title Not Found (#404)
I tried everything from changing the .htaccess to changing the url
how can I solve that?
I noticed that there are no index.php in the website base folder and as if all the requests are going to the front end
Even I have installed a fresh copy of Yii2 advanced and following standard steps I got everything OK. But the same problem like you mentioned here that the backend was not working.For this I added an additional .htaccess file inside backend folder(/backend) with the following code:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
Please do follow and I hope it helps.Your config settings must be correct in addition to 1 more .htaccess inside backend/web folder with the following code:
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php

Using .htaccess to RewriteRule but every file points to one file

I am currently trying to using .htaccess to do the following:
When b/ is found in the url, it redirects to browse.html. My .htaccess file looks like:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^b/(.*)$ browse.html [NC,L]
I am using Apache version 2.2.31 and here is what my directory looks like:
Root
Root/browse.html
Root/[css]
Root/css/browse.css
Root/[js]
Root/js/browse.js
When I do this, it brings me to browse.html but nothing loads correctly. Every file in the css and js directories become browse.html. Is there something extra I need to add to this?
Here is what the dev tools directory looks like with the .htacess
localhost
b/?page=1 (browse.html file. Name comes from query string)
b/[css]
b/css/browse.css (blank file)
b/[js]
b/js/browse.js (browse.html instead of browse.js)
I have tried putting RewriteBase / in between but that does nothing to the problem.
Your rewrite rule is fine. Problem is happening due to your use of relatives paths for css/js/images. While resolving relative paths browser appends it to current page's path.
You can add this rule above your existing rule::
RewriteEngine On
# fix css/js paths
RewriteRule ^b/.*((?:js|css)/.+)$ /$1 [NC,R=301,L]
RewriteRule ^b/(.*)$ browse.html [NC,L]
Make sure to ignore requests if files/folders exists:
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^b/(.*)$ browse.html [NC,L]

How do I redirect "website/page" to "website/page.html" when people type it in browser (pretty-url)

I recently started using a static site with godaddy.com without a cms. It's a basic website I uploaded and is only html/js/css.
When people type "website.com/page" they get 404 not found.
When they type "website.com/page.html" they get the correct page.
How can I fix my site so users can simply type "website/page" and not be forced to type "website/page.html" without using php?
SOLUTION
After researching the information about .htaccess files provided by #Gijsberts (thank you), I did the following:
Created a .htaccess file on server.
Added the following code:
# Remove the .html extension from html files
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
Most CMS systems have a .htaccess file what handles the redirect and the 404 errors. In CMS system they are most called "Pretty-urls". Read the links below to set up those pretty urls yourself with a static web page without a cms.
https://mediatemple.net/community/products/grid/204643080/how-do-i-redirect-my-site-using-a-htaccess-file
http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
You normally can do this with your Webserver config. In Apache you have this enabled automatically. In nginx you should have a look at this tutorial.
If you are using caddy you have to config your caddyfile like
ext .html .htm .php
if you are using microsoft iis have a look at microsofts tutorial.
Let me know if you are using something else or need more help.
EDIT
If you are using a webspace you may are not able to change the config of the webserver. you now can use .htaccess. create a .htaccess file and write down something like
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Laravel 4 in a subfolder

I have a test project on Laravel 4, and I'm still new to this. I'm still working on wamp (localhost). I have already made it work as long as laravel is installed on the root path of wamp (..wamp/www), but when I try to create another folder (..wamp/www/testproject) and install laravel there, the routes are not working anymore except for localhost/testproject/laravel/public.
to summarize:
--The working one---
C:/wamp/www/laravel = the folder where laravel was installed
localhost/laravel/public = working, "You have arrived" page
localhost/laravel/about = working about.php route
--The one with errors--
C:/wamp/www/testproject/laravel = the folder where laravel was installed
localhost/testproject/laravel/public = working, "You have arrived" page
localhost/testproject/laravel/about = not working about.php route
localhost/testproject/laravel/index.php/about = working, and I don;t know why
can someone help me with this? why is it that the "about.php" page is not working on the subfolder? :(
EDIT: .htaccess file content
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
here is the screenshot for the routes..
Add RewriteBase /laravel/public below RewriteEngine On in .htaccess