fuelphp routes to angular routes - javascript

I have routes and request handling mechanism written in fuelphp to calculate the template in server side.
Computing templates on server side is slower in my understanding and I would like to covert all routes to angular routing.
Most of the fuelphp code outputs angularjs views.
Is there a direct or quicker way to convert all php routes to angular routes.

Try this:
In your public folder make a .htaccess file and fill it with the following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

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 for React app using React router hosted on cpanel

So I have a react single page application that I am hosting on cpanel. I have a pretty common issue from what I have been researching but none of the post in SO have helped me so far.
I am using React Router which I know is purely client-side routing. The problem is when the user refreshes the page on a url such as https://example.com/privacypolicy I get the stand Not Found error 404.
My folder structure in cpanel is as follows:
home/mysite
public_html
all the folder from build folder (after npm run build locally)
index.html(important for the post)
.htaccess(important for the post)
The htaccess file is as follows:
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
I was hoping this was going to redirect all the requests to index.html and therefore react would know which component to render once that has been redirected.
It isn't and I'm a bit lost on what I'm doing wrong.
Any help is appreciated :)
To host ReactJS website on cPanel it is important to use homepage attribute in your package.json. For example, you can use:
"homepage": "http://example.tld"
Once you are done with setting up the homepage attribute, then run the npm build command to compile your code.
npm run build
This command will generate a folder named build in your project's root folder. Then upload the build folder contents to cPanel and use the below .htaccess file configuration.
<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>

Problem when my React App is put on the web

I have created my React App, npm run build ... Put my file in filezilla,
but the problem is that I have this error
Not Found
The requested URL /main was not found on this server.
when I go to a page other than https://clickswinner.alwaysdata.net
What are you propose ?
Try creating a .htaccess file and put it at root of your server
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
</IfModule>
Google is your friend
Here is an article about how to fix 404 issues for Filezilla
https://medium.com/#christine_tran/deploying-a-simple-react-application-using-ftp-filezilla-dreamhost-1e5ff6b8abd6

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

Automatically adding SourceMap headers for JavaScript requests

I've started playing around with SourceMaps and am wondering if there's a way to automatically set the appropriate header automatically if a .map file exists for a JavaScript request using .htaccess instead of having to modify the original JavaScript file.
I already do something similar to serve minified JavaScript if it exists and I'm not debugging:
RewriteCond %{REQUEST_FILENAME} \.(php|js)
RewriteRule . - [E=DEBUG:true]
RewriteCond %{ENV:DEBUG} !^true$
RewriteCond %{REQUEST_URI} ^(.+)\.js$
RewriteCond %{DOCUMENT_ROOT}%1-min.js -f
RewriteRule . %1-min.js [L]
I guess it basically boils down to: how can I add an extra HTTP header if a certain file exists for a certain type of request?
UPDATE
The solution is as follows:
# If serving minified js and a SourceMap file exists, send appropriate header
RewriteCond %{REQUEST_URI} ^(.+-min\.js)$
RewriteCond %{DOCUMENT_ROOT}%1.map -f
RewriteRule . - [L,E=SOURCE_MAP:%{REQUEST_URI}.map]
Header set X-SourceMap "%{SOURCE_MAP}e" env=SOURCE_MAP
See edit made by Nev Stokes above for the final solution
RewriteCond %{REQUEST_FILENAME} \.(php|js)
RewriteRule . - [E=DEBUG:true]
RewriteCond %{ENV:DEBUG} !^true$
RewriteCond %{REQUEST_URI} ^(.+)\.js$
RewriteCond %{DOCUMENT_ROOT}%1-min.js -f
RewriteRule [^/]+\.js$ %1-min.js [L,E=SOURCE_MAP:%{REQUEST_URI}]
Header set X-SourceMap "%{SOURCE_MAP}e" env=SOURCE_MAP
I could not test the Header part as my test server doesn't have mod_headers installed.

Categories