TCPDF cache problems when using https - .htaccess

We have been using TCPDF to create PDFs on the fly for a while now and everything has been working fine.
However, we changed to https today using the following htaccess code:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.berau.at/$1 [R,L]
Now we are getting the following TCPDF error:
TCPDF ERROR: [Image] Unable to get image: /home/.sites/64/site1783/web/pdf2/cache/img_UgqqR0
If we remove the htaccess redirect for https, everything works fine again.
We've searched the TCPDF website, but no references to https problems there.
The TCPDF cache folder already has 755 permissions!
Here's the code we're using to call the image:
$img_file = $rs_produkt[20];
$pdf->Image($img_file, 0, 0, 0, 0, '', '', '', false, 300, '', false, false, 0);
Thanks in advance for any help!

Here's the solution to our problem:
Line 23847 in tcpdf.php contains a direct reference to http. Change this line from
if (preg_match('%^/{2}%', $tag['attribute']['src'])) {
$tag['attribute']['src'] = 'http:'.$tag['attribute']['src'];
}
to
if (preg_match('%^/{2}%', $tag['attribute']['src'])) {
$tag['attribute']['src'] = 'https:'.$tag['attribute']['src'];
}
and everything works fine.

Related

How to redirect to URL with trailing slash in warp?

I am using warp to serve a directory of static files. Unfortunately the relative links used in those static files can only be resolved, when I add a trailing slash to my path.
This is the code I use to serve the directory:
let route = warp::path("segment")
.and(warp::path("another"))
.and(warp::fs::dir("../path/to/static/files/folder"));
warp::serve(route).run(([0, 0, 0, 0], 3030)).await;
So now
0.0.0.0:3030/segment/another/ works fine
0.0.0.0:3030/segment/another does not work
In principle I would not mind this and just always use the URLs with trailing slashes, however when I "Add to Homescreen" the page from Safari on iOS (as a PWA) the trailing slash is ommited automatically.
So in order to work around this, I tried to create a redirect, and then add the trailing slash like this:
let redirect = warp::path("segment").and(warp::path("another")).and(warp::path::end())
.map(|| {
warp::redirect(Uri::from_static("0.0.0.0:3030/segment/another/"))
});
however this redirect filter only matches 0.0.0.0:3030/segment/another/. When I omit the warp::path::end() the redirect works for 0.0.0.0:3030/segment/another but now everything (for example 0.0.0.0:3030/segment/another/styles.css) gets redirected to 0.0.0.0:3030/segment/another/.
Is there a way to only redirect when the path does not end with a slash or a file extension (e.g. .html, .cssetc.)?
It might be that my overall aproach is incorrect here, too.

How to do a redirect in Laravel for ads.txt

Google wants have access to ads.txt file like "example.com/ads.txt", but in Laravel we need redirect it to "public" folder.
How do it?
I try RedirectMatch 301 ^ads\.txt$ \/public\/ads\.txt, but it doesn't work.
Put your ads.txt file in the folder: public (for Laravel), then it will be accessible to the link: example.com/ads.txt . I have made on my laravel website and it's working fine
I have solved the issue in following way.
In my web route file:
Route::get('/ads.txt', function () {
$content = view('ads');
return response($content, 200)
->header('content-Type', 'text');
});
and I have rename the ads.txt file to ads.blade.php
Or Simply add your ads.txt file inside public folder of your application it will work fine.
You can create blade file has name ads.blade.php and put all text from ads.txt to this blade , and create route like that :
Route::get('/ads.txt',function(){
return view('ads');
});
I tried that when register my website in google

Page not found "/" route

I'm trying to setup a VueJS app using Nuxt for server side rendering. However after deployment to my server the index.vue is return a 404 Page not found error.
This doesn't happen when run on my development machine, and still happens even if run in Development mode on my server.
All other routes work, and getting to the index route from within the app itself works fine. It just doesn't load when refreshed. Eg:
http://myapp.com/ Doesn't work
http://myapp.com/login Works fine
My pages folder currently looks like this:
- pages
-- index.vue
-- login.vue
I have nothing fancy set up within my nuxt.config file and have pretty much the same setup as is described in the Auth0 example
On my server I'm running nuxt with the command pm2 start npm --name "my-app" -- start Which runs fine without any errors, and I have the following .htaccess config:
RewriteCond %{HTTP_HOST} ^my-app\.com$ [OR]
RewriteRule ^(.*) "http\:\/\/127\.0\.0\.1\:3000\/$1" [P,L]
This is the error screen I get:
The page itself is very basic at the moment, it did have far more on it however I've cut it down to the following trying to debug this issue:
<template>
<v-container grid-list-md>
<v-layout row wrap>
<h1>Test index, trying to fix the 404</h1>
<h2>Hello, {{ loggedUser ? loggedUser : 'friend' }}!</h2>
</v-layout>
</v-container>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
computed: mapGetters([
'isAuthenticated',
'loggedUser'
])
}
</script>
I seem to have managed to fix this. However, I'm not completely sure on the cause the fix involved modifying my .htaccess. I started playing with the settings and ended up with the following which works well (for now at least).
RewriteCond %{HTTP_HOST} ^my-app\.com$
RewriteRule "(.*\.(jpg|gif|png|svg|js|css))$" "http://127.0.0.1:3000/$1" [P,NC]
RewriteRule ^(.*) "http\:\/\/127\.0\.0\.1\:3000\/$2" [P,L]
The rule for jpg|gif etc is required as they don't load when using the second rule.

Get project base url that works in XAMPP and on production, considering .htaccess

I have a project that is not in the root of the XAMPP folder:
htdocs/my-folder/projects/my-project
htdocs/my-folder/projects/my-project/index.php
htdocs/my-folder/projects/my-project/js/
htdocs/my-folder/projects/my-project/css/
that folder contains an index.php file from where I try to call stylesheets and scripts. Initially, I'd just do it like this:
<script src="js/myscript.js"></script>
which worked. However, the project has expanded and now a user can "save" the current page (similar to how JSFiddle does it), and the URL will look different. Upon a first save a random string will be appended as a conf parameter, which results in something like this (locally) and should have a public equivalent:
localhost/my-folder/projects/my-project?conf=abcd # locally
http://mywebsite.com/projects/my-project?conf=abcd # publicly
Upon second save, the URL gets an additional parameters, a version number:
localhost/my-folder/projects/my-project?conf=abcd&v=2 # locally
http://mywebsite.com/projects/my-project?conf=abcd&v=2 # publicly
But, to get a nice URL I use this .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (\w+)[/](\d+)$ ?conf=$1&v=$2 [L,NC]
which will result in something like this:
localhost/my-folder/projects/my-project/abcd/2 # locally
http://mywebsite.com/projects/my-project/abcd/2 # publicly
The thing is, when the URL is changed to some structure as above (without the parameters, but with the rewritten URLs, e.g. localhost/my-folder/projects/my-project/abcd/2) then the initial call to the resources (scripts, styles) in my index file won't be correct any longer.
In other words, if this is the url: localhost/my-folder/projects/my-project/abcd/2 then the server will look for a a script file in localhost/my-folder/projects/my-project/abcd/2/js/myscript.js, which is obviously wrong.
The question, thus, is: how can I get the absolute path to the current file, but that also works in XAMPP (so not __FILE__ or __DIR__ which will dig in the file strucure and return file://) and also on production environments.
You'll have to use the base element in your pages. The usage will be something like:
<base href="/projects/my-project/" />
for the public server and
<base href="/my-folder/projects/my-project/" />
locally.
I hackingly figured it out. By checking the end of the url, we determine if we are in root or if we are in a specific instance (ending with a digit e.g. /1.
<?php
// Is connection secure? Do we need https or http?
// See http://stackoverflow.com/a/16076965/1150683
$isSecure = false;
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$isSecure = true;
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])
&& $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'
|| !empty($_SERVER['HTTP_X_FORWARDED_SSL'])
&& $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$isSecure = true;
}
$REQUEST_PROTOCOL = $isSecure ? 'https' : 'http';
$REQUEST_PROTOCOL .= '://';
// Create path variable to the root of this project
$path_var = $REQUEST_PROTOCOL.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
// If URL ends in a slash followed by one or more digits (e.g. http://domain.com/abcde/1),
// returns a cleaned version of the URL, e.g. http://domain.com/
if (preg_match("/\/\d+\/?$/", $path_var)) {
$path_var = preg_replace("/\w+\/\d+\/?$/", '', $path_var);
}
?>
Now we can use it in our PHP file!
<link href="<?php echo $path_var; ?>css/styles.css" rel="stylesheet">

why does index.php shows up in url, when site loads for first time (yii)

I have used my htaccess file and yii rules to hide the index.php from my url, it all works fine apart from the 1st time when the site loads, index.php can be seen in the url. Can anyone shed any light on why this may be happening? Have a look at www.whitecollarboxinglondon.com
Thanks.
Karen.
Try the following configuration in your URL Manager:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
..............................
..............................
)

Resources