We have built an application with AngularJS, it is currently hosted on a shared cPanel hosting. However, whenever we do a refresh on any page we are at with ? in the url. It will break.
I have read extensively on Stackoverflow, I understand it is because of the browser doesn't know which page to load and hence we need to set the base url in the header. We tried setting the base url and did some htaccess settings but it is still not working.
Try to click on any link from the website and refresh that page. You will notice it failed to work.
Any kind soul can point us to the right directions on how we can solve this?
Edit 1:
I have these in htaccess and notice the only url with ? will refuse to load correct.
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/api
# otherwise forward it to index.html
RewriteRule ^.*$ - [NC,L]
RewriteRule ^/* /index.html [NC,L]
I tried to reproduce the Issue but its not showing any # tag in the URL as mentioned. Can you please explain in details.
The issue didn't come from htaccess but the folder name. For instance,
config(function($stateProvider) {
$stateProvider.state('search', {
url: '/search?page&loc&seaters&owner&min_price&max_price',
The problem is when our folder is also call search, Apache will attempt to go to search folder first (due to the htaccess) and because they can find the folder, it will read the folder directory.
We fixed it by naming the folder example: search-html and change all the templateUrl required to search-html and it solves the issue.
Related
Hey has anyone experienced issues with react-router on a production build. I'm running a LAMP server and I've built my project put it in the http folder and when I go to a page I get Object not found!. I have setup react-router to go to certain pages based on certain conditions if I go to the root of the server i.e. localhost/ it loads the main page but then if I click on links it works fine as soon as you try and manually go to a link by typing in the search box I get the error message Object not found
This is my .htaccess file
<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>
You need to configure your server to return index.html if file not found (404).
Example:
Let's say you have /users route the will show your users list.
It will be ok if first you'll go to / (which will return index.html by default) and then click some router link and it will redirect you to that page. It will work because you wont make any additional requests to the server.
But if you go to /users first - you'll request it from the server. In that case server will try to find users file and it will not be there.
If this configuration is not possible consider using hash router. The url will look like this /#/users
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
Hopefully, this is not duplicated.
I´m trying to bring structure to my site and be clean, I´m separating content. It is an angular app, I´mean 2 apps in one domain separated thru the folder name
So I´m trying following:
domain.xy/folder
should internal redirect to
domain.xy/anotherfolder
after that, I´m using angular hashtag links and I don´t want them to be shown. When the file or folder doesn´t exist then add a #
domain.xy/link1
becomes to
domain.xy/#/link1
I´m trying around with this code, and it´s working fine if not separated. I thought When the first rule passed with flag [L] It will do another loop with the rewritten URL but Here I got the error that this is not working, and like he is not passing the first rule when I type something like
domain.xy/folder/link1
This is the latest code I was trying. Maybe someone sees the error in my thinking and give me a hint or advise? Thanks in advance.
RewriteEngine On
Options FollowSymLinks
RewriteBase /
# Rewrites folder
RewriteRule ^supplier/(.*)$ /_supplier/$1 [L,NC]
RewriteRule ^agency/(.*)$ /_agency/$1 [L,NC]
# Folder doesn`t exist then it is a angular link
# rewrite with # tag
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]
I found myself with a false use of angular $locationProvider.html5Mode(true); and rewriting URLs.
I changed now the structure for the use of hashbang in my project. Now it's working correctly.
Thank you all for viewing.
I'm wondering what I've done incorrectly or what I'm missing. I'm trying to use html5mode with my base href as a subdirectory. If I go to a route off of that base and reload, the page tries to jump back to before the subdirectory.
If that doesn't make any sense, let me show you how I've configured...
In my app.js file I have set:
$locationProvider.html5Mode(true)
In my index.html file, in my tag I've set:
<base href="/subdirectory/">
Thus, if I navigate to http://url.com/subdirectory all is good.
If I then click a link to visit http://url.com/subdirectory/subpage, all is good.
However, if I RELOAD the subpage, OR, if I try to navigate directly to that subpage, it will not render. In fact, I believe the browser thinks it's trying to start back at http://url.com instead of starting from http://url.com/subdirectory/
Can someone who's experienced a similar problem explain a solution to this?
I've been banging my head against the wall. I'd really appreciate it. Thanks!
You have to configure your server to redirect all requests to http://url.com/subdirectory/subpage to the same location as http://url.com/subdirectory/ points to.
So this was the solution.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /subdirectory/index.html [NC,L]
</IfModule>
When loading a page using Angular an Apache myserver.com everything works fine, when going to a subroute from the main page myserver.com/credits by clicking a link it'll work as well.
However, if I try to go directly to myserver.com/credits from the browser navigation bar it'll return a 404 error message:
I'm aware that by working with node I can configure this so that it does work, however, my company website runs in an apache server which I have no access to.
I could make it so the server redirects to the main page myserver.com like so:
.htaccess
ErrorDocument 404 /index.html
However the optimal resolution would be that going to myserver.com/credits works outright.
Is there a way to make Apache behave this way? And if so, how?
The answer that solves this question can be found here:
https://stackoverflow.com/a/22740184/1224232
I have flagged this question as a duplicate. I have tested it and it works perfectly.
Special thanks to Kevin B for directing me to the answer, and to Rajasaur for providing the answer.
Created a .htaccess file in root directory if not exist.
then add the following code in it
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# not rewrite css, js and images
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ /index.html?path=$1 [NC,L,QSA]