shared SSL + cakePHP, path question - cakephp

https://abc.hostingcompany.com/~myusername/img/test.jpg //works, shows the test image
https://abc.hostingcompany.com/~myusername/contact //404 error
http://www.mydomain.com/contact //works as expected, so why dosent #2?
I dont understand how cakePHP 'pages' can be routed to, using SSL.
As I understand it, using relative paths is what you are supposed to do, which I have done. I know there is a component built into cakePHP for security, but for now, just getting the (for example) https version of the contact page link to work is perplexing me.

In my research, I discovered that you can use .htaccess command RewriteBase to convert between the shared version of the URL and the cakePHP version of the url.
I also learnt that relative pathing is important, and that /img/test.jpg is not the same as img/test.jpg (One assumes the root, the other does not).
As long as Im sharing what I found out... (yeah, noob material here... Id like to see any other page on the net with all this in the same spot)
The https version is the same code (pulled from the same folders I mean) as the http code.
Turning on (using) and off https is as simple as a link to https://[yoursite] and http://[yoursite].
And a shoutout to the people at apacheserver.net ripping this off stackoverflow.com. (Its already in the google search results... holy cow)

Related

Load index.html for every possible route of my React SPA that is hosted on digitalocean spaces

I use digital ocean space and CDN to host a React SPA. When hitting with a browser the url [host]/index.html it works fine. However hitting [host]/index.html/customers/one or any other subpaths, returns a 404. Currently, any reload on any subpath returns that 404. Last, I use terraform to update the SPA artifacts on DO spaces and I have tried to add a website_redirect="/index.html" to all the bucket objects (js, html and css) but with no success (more info if necessary here). And to be completely honest I am not sure I understand that option in the terraform digitalocean provider. I might be using it completely wrong.
Now, I have seen that question in multiple places but never with a clear answer.
Here is one on digitalocean community (https://www.digitalocean.com/community/questions/is-it-possible-to-send-a-301-redirect-for-bucket-objects) where no answer is provided but the issue seems to be similar.
There is a similar question on SO without an approved answer Redirect wrong URL/path DigitalOcean Spaces
This is a DO idea that is somewhat related https://ideas.digitalocean.com/ideas/DO-I-318
Is there a way to achieve the mentioned goal of loading index.html for every route with DO space + CDN and let the app parse the rest of the path to display the right component subtree of the react app?

How can I properly use HTML5 url with AngularJS?

I'm pretty new with AngularJS and server config stuff, and this is a problem I haven't found a satisfactory solution so far.
I would like to be able to use the HTML5 url on a website (without hashbangs), so that I could use addresses like "mydomain/contact" to navigate (I'll stick with the "contact" example for simplicity).
To do that, as I've found so far, one should do two things:
Enable HTML5 on the client side
Enable the HTML5 format on the app/app.js file (also adding the dependency)
$locationProvider.html5Mode(true);
It makes possible to click on links and get the proper url. Still, it doesn't allow someone to access directly the HTML5 url. To get to the "contact" page, I still can't directly access "mydomain/contact" (we get a 404) and I know it makes sense. To solve this, it is still necessary to implement something server-side.
Server-side config
Configure the server to respond with the right file, i.e., I should configure the server to make it respond the same way when I request "mydomain/#/contact" and "mydomain/contact".
The last item is where I'm stuck. I've found many answers like this: "you should configure your server" (they assume the reader already knows how to do this. I don't), but I can't find a complete example on how to do that or where to put any needed files.
I'm using AngularJS 1.6.x and npm 3.10.9 (npm start). My question is: is there any complete example on how to fully use HTML5 urls with AngularJS?
The only problem that exists is that angular can't handle requests it doesn't receive. You need some catch-all so that all routes (/contact etc) are passed to your main index-file.
When you say .htaccess I assume apache. Even so I'd still put nginx in front of apache since it's lightweight and easy to configure (at least compared to the apache behemoth). Sorry, I know that is a very opinionated answer. Anyway with nginx the entire config could look like this:
# usually this file goes in /etc/nginx/conf.d/anyfilename.conf
# but it might vary with os/distro.
server {
listen 80
root /var/www/myapp;
location / {
try_files $uri $uri/ index.html;
}
# And if you want to pass some route to apache:
location /apache {
proxy_pass http://127.0.0.1:81; # Apache listening on port 81.
}
}
I'm sure the same can be achieved with apache alone, but I couldn't tell you how. But perhaps this can be of help: htaccess redirect for Angular routes
There are so many silly toolpacks and utilities I've wasted time learning in my life, but nginx is the one tool I'll never regret I picked up.

CakePHP: Can only load index.php, all pages 404 after Cake Bake

I'm trying to bake my first CakePHP application and am unable to get any page to particularly load for me right now. I've updated my config settings for salt,database, etc. and the index.php page tells me that I have configured everything.
So far I've used cake bake all on just one database table so far to make sure it loads properly. I created the Model, Controller, and View for the standard add/index/view/edit pages. When I try to access URL/organizations/index.php I'm hitting a 404 error however.
Is there any troubleshooting someone might have advice for how to solve this one? It is confusing to me that the index.php loads (so it redirects properly when loading the webroot) but trying to view any View pages yields no results. Is there any debug commands I can do to view what the valid pages would be? Or any additional information I can provide?
If you try URL/index.php/organisations or something similar to this and it works, then there is an issue with URL re-writing on the server which you'll need to correct.
I believe if you have things set up correctly you would want to visit /organizations in order to access the index() method of the organizations controller.
In general the ".php" is left off of the URL, as your index.php file initiates all the bootstrapping and routing. This also requires a correct .htaccess setup. Hard to say exactly what the problem is without seeing the app or an error message.
Try in url
URL/organizations/index.php
To
URL/organizations/index
or
URL/organizations/index.ctp
Cakephp using .ctp extension, that means cakephp Template. Please see this link. And also you can see your app\view\Organizations folder. Here all file is with .ctp extension. Isn't it ?

cakephp alias url

The url structure of my cakephp based site is mysite/cakephp/myapp/index.php/controller/action/input_paramaters
I cannot remove index.php from my url, as I dont have access to httpd.conf file.
Anyways, my question is that I just need to change the url of my homepage to something like http://mysite or mysite/myapp
How would I do that?
Thanks a lot!!
The problem sounds to me that you don't have mod_rewrite enabled or Apache AllowOverwrite is not set properly.
If you don't have mod_rewrite then you cannot change the urls with the pretty ones (provided from CakePHP).
If the AllowOverwrite is not set to On. Then even if you have mod_rewrite enabled, the .htaccess files in your directories doesn't take effect.
I don't know which is worst. Speak with your hosting provider and ask for help.
It is not really clear to me which part of the URL changes. CakePHP routing applies only relative from the cake directory. So if you move from http://example.com/foo to http://www.example.org/bar nothing needs to be changed in Cake.
However you might have hardcoded some img/CSS/JS URL-s that needs some work now. I also use the HTML base tag so my app works perfectly fine under various base URL-s.

Cannot Call WordPress Plugin Files Under wp-content

I have a client who has many blog customers. Each of these WordPress blogs calls a plugin that provides a product link. The way that link is composed looks like this:
{website}/wp-content/plugins/prodx/product?id=432320
This works fine on all blogs except two. On those two, when you try to call the URL, you get a 404.
So, I disabled all plugins except prodx and reverted the theme to default (Kubrick), thinking perhaps a plugin intercept with add_action() API was doing this, such as intercepting URLs and redirecting them. However, this did not help.
So, I upgraded the WordPress to the latest version. Again, didn't fix.
So, I checked permissions, comparing with a blog that worked just fine. Again, didn't fix.
So I replaced the .htaccess, using one from a working blog. Again, didn't fix.
So I replaced all the files using some from a working blog that was identical to this one, and then restored the wp-config.php file back so that it talked to the right blog database. Again, didn't fix.
Again I checked permissions meticulously, comparing to a perfectly working blog. Again, didn't fix.
So, I created a test.php that looks like so:
<?php
print_r($_GET);
echo "hello world";
I then copied it into another plugin folder and used my browser to get to it -- again, 404. So I copied it into the root of wp-content/plugins and tried to call it there -- again, 404. So I copied it into wp-content -- again, 404. Last, I copied it into the root of the WordPress blog website, and this time, it worked!
Doesn't make sense.
I started to think that perhaps something was going on with /etc/httpd/conf/httpd.conf for this customer, but the only thing I saw different in their for this customer was the IP address was different than the customer's blog that worked. Each customer gets their own IP in this environment my client has built.
My client sysop is baffled too.
What do you think is going on? Is there something wrong in the WP database for this customer? Is there something wrong in httpd.conf?
You could check for bad URLs in plugins' options in the WP options table using phpmyadmin (and compare other aspects of each blogs' options) which might be already available at your host, or as a plugin: WordPress › Portable phpMyAdmin « WordPress Plugins. Or delete the plugins' options with Clean Options to completely "reset" the plugin (if the plugin uses options): Clean Options « WordPress Plugins
You should look into your server's error log, there should be an explanation. If not, turn up debugging levels etc. That said, the plugin really shouldn't link to the file in the plugin dir, it should use the wordpress rewrite class http://codex.wordpress.org/Function_Reference/WP_Rewrite
I think the problem was that the URL was too long. Here's some great info about that:
http://www.boutell.com/newfaq/misc/urllength.html
And for some reason the blog was getting a 404 instead of a 413.
The fix was that I used gzcompress to shorten my long product ID (which was a cloaked URL), then bin2hex. So I made the URL like so:
http://myblog.com/item/789ccb282929b0d2d72f2f2fd7cb4ac92fcc4faed44bcecfd54fcec94cced63536373334b730d7353430333334b530b60f0df2b1cd00ea503576543572032290befcb2d4a2e292fce46c904e90b0b15b1a50854b9aaa915980a3bb2b901910e4ef12ea1c0214f00f0ef60e058a181a199b5b18999b0100194725b4
From there, I had my plugin add an init handler to hijack the URL, inspect it, and redirect. That function looks like this:
add_action('init','hijackURL');
function hijack_URL() {
$sURL = $_SERVER['REDIRECT_URL'];
if (empty($sURL)) {
$sURL = $_SERVER['REQUEST_URI'];
}
if (strpos(' ' . $sURL, '/item/')>0) {
$sID = str_replace('/item/','',$sURL);
$sID = trim($sID);
if (empty($sID)) {
require('../../../wp-blog-header.php');
$sBlogURL = get_bloginfo('wpurl');
header('HTTP/1.1 302 Moved Temporarily');
header("Location: $sBlogURL");
exit(0);
}
$sID = pack('H*', $sID);
$sURL = gzuncompress($sID);
header('HTTP/1.1 302 Moved Temporarily');
header("Location: $sURL");
exit(0);
}
}

Resources