Closed 360fusion closed 9 years ago
The default share links for Facebook and Twitter use Contao's share/index.php
. It seems there is a directive in place on your website, that rewrites or redirects this request and causes a 404 Page not found
response from Contao. Or the file share/index.php
is simply not present in your Contao installation?
Can you post the content of your .htaccess
?
If this is not solveable, you could also change the sharer URL for twitter and facebook to their native ones. e.g. instead of
share/index.php?p=facebook&u=<?php echo $this->url; ?>&t=<?php echo $this->title; ?>
you could use
http://www.facebook.com/sharer/sharer.php?u=<?php echo $this->url; ?>&t=<?php echo $this->title; ?>
And instead of
share/index.php?p=twitter&u=<?php echo $this->url; ?>&t=<?php echo $this->title; ?>
you could use
http://twitter.com/share?url=<?php echo $this->url; ?>&text=<?php echo $this->title; ?>
Hi, Thanks for getting abck to me so quickly. I'm not sure why the sharer file would do that, I haven;t made any changes that I know of. Here is my htaccess file:
Link to paste bin: http://pastebin.com/wchdbs0H
Yikes, you should put the content of the .htaccess
file in three back-ticks ( https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code ) ;). Or post it on pastebin. Did you make sure, that the file share/index.php
is existent in your Contao installation?
Hi,
sorry, done that now.
Yep. share file is there.
Ben
In my share/index.php the share links seem to be native?
if (Input::get('p') == 'facebook')
{
$query = '?u=' . rawurlencode(Input::get('u', true));
$query .= '&t=' . rawurlencode(Input::get('t', true));
$query .= '&display=popup';
$query .= '&redirect_uri=http%3A%2F%2Fwww.facebook.com';
header('Location: http://www.facebook.com/sharer/sharer.php' . $query);
exit;
}
/**
* Twitter
*/
elseif (Input::get('p') == 'twitter')
{
$query = '?url=' . rawurlencode(Input::get('u', true));
$query .= '&text=' . rawurlencode(Input::get('t', true));
header('Location: http://twitter.com/share' . $query);
exit;
}
Your .htaccess
has definitely been altered. It contains changes so that your URLs can be without a suffix (e.g. without the default .html
suffix). However, the change is incomplete, that's why it's impossible to make a request to share/index.php
on your website.
Specifically, you need to add
RewriteCond %{REQUEST_FILENAME} !-d
before
RewriteRule .* index.php [L]
This is documented in the default .htaccess
file of Contao itself:
# If you do not want to use an URL suffix at all, you have to add a second
# line to prevent URLs that point to folders from being rewritten (see #4031).
#
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule .* index.php [L]
(in newer Contao versions it says "third" instead of "second", since it's actually a "third" line now)
I have just replaced the .htaccess file with an unedited original one and changed the rewrite urls to use .html in settings
I'm still having an issue: http://belviso.360fusionhosting.co.uk/blog/id-2015-dates-for-ipaf-3a-and-3b-training.html
Now http://belviso.360fusionhosting.co.uk/share/index.php ( and http://belviso.360fusionhosting.co.uk/share ) is redirecting to http://belviso.360fusionhosting.co.uk/index.php (with 301 Moved Permanently). You need to find out why this is happening on your site/server.
Why do all the other share links work and it's only twitter and facebook that don't? Surely if one works they all should?
Why do all the other share links work and it's only twitter and facebook that don't? Surely if one works they all should?
No, as I said, the share links for Facebook and Twitter use Contao's own share/index.php
- and this file is not accessible on your server. As I pointed out you can circumvent the issue by using the native share links for Facebook and Twitter instead (but it would be good to find out why this redirect is happening, since it can potentially cause other issues on your website).
Ok.
Yes, I don need to find that out. hhhmmm. Any ideas?
Ah sorry, I was mistaken, the share/index.php
does not create a permanent redirect (well it does, but only if you do not pass any parameters, which is by design) - but now if you try to call http://belviso.360fusionhosting.co.uk/share/index.php?p=facebook&u=http%3A%2F%2Fbelviso.360fusionhosting.co.uk%2Fblog%2Fid-2015-dates-for-ipaf-3a-and-3b-training.html&t=2015%20Dates%20for%20IPAF%203a%20and%203b%20Training! for instance, it results in a 501 Server error. I don't know why this could happen. Maybe your server does not allow to send header("Location: …");
back to the client with an URL that is not on the server's domain or something like that?
Well in any case, here is an altered sharebuttons_default
template, which uses the native sharer URLs:
<!-- indexer::stop -->
<div class="sharebuttons">
<ul<?php if( $this->theme ): ?> class="theme <?php echo $this->theme; ?>"<?php endif; ?>>
<?php if ($this->facebook): ?>
<li><a class="facebook" href="http://www.facebook.com/sharer/sharer.php?u=<?php echo $this->url; ?>&t=<?php echo $this->title; ?>" rel="nofollow" title="<?php echo $this->lang['share_on_facebook']; ?>" onclick="return shd.open(this.href,600,300);">Facebook</a></li>
<?php endif; ?>
<?php if ($this->twitter): ?>
<li><a class="twitter" href="http://twitter.com/share?url=<?php echo $this->url; ?>&text=<?php echo $this->title; ?>" rel="nofollow" title="<?php echo $this->lang['share_on_twitter']; ?>" onclick="return shd.open(this.href,500,260);">Twitter</a></li>
<?php endif; ?>
<?php if ($this->gplus): ?>
<li><a class="gplus" href="https://plus.google.com/share?url=<?php echo $this->url; ?>" rel="nofollow" title="<?php echo $this->lang['share_on_gplus']; ?>" onclick="return shd.open(this.href,520,450);">Google+</a></li>
<?php endif; ?>
<?php if ($this->linkedin): ?>
<li><a class="linkedin" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo $this->url; ?>&title=><?php echo $this->title; ?>" rel="nofollow" title="<?php echo $this->lang['share_on_linkedin']; ?>" onclick="return shd.open(this.href,520,570);">LinkedIn</a></li>
<?php endif; ?>
<?php if ($this->xing): ?>
<li><a class="xing" href="https://www.xing.com/social_plugins/share/new?sc_p=xing-share&h=1&url=<?php echo $this->url; ?>" rel="nofollow" title="<?php echo $this->lang['share_on_xing']; ?>" onclick="return shd.open(this.href,460,460);">Xing</a></li>
<?php endif; ?>
<?php if ($this->mail): ?>
<li><a class="mail" href="mailto:?subject=<?php echo $this->lang['mail_subject']; ?>:%20<?php echo $this->title; ?>&body=<?php echo $this->url; ?>">Mail</a></li>
<?php endif; ?>
<?php if ($this->tumblr): ?>
<li><a class="tumblr" href="http://www.tumblr.com/share?v=3&u=<?php echo $this->url; ?>&t=<?php echo $this->title; ?>&s=<?php echo $this->description; ?>" rel="nofollow" title="<?php echo $this->lang['share_on_tumblr']; ?>" onclick="return shd.open(this.href,800,450);">tumblr</a></li>
<?php endif; ?>
<?php if ($this->pinterest && $this->image): ?>
<li><a class="pinterest" href="http://pinterest.com/pin/create/button/?url=<?php echo $this->url; ?>&media=<?php echo $this->image; ?>&description=<?php echo $this->description; ?>" rel="nofollow" title="<?php echo $this->lang['share_on_pinterest']; ?>" onclick="return shd.open(this.href,460,460);">Pinterest</a></li>
<?php endif ;?>
<?php if ($this->reddit): ?>
<li><a class="reddit" href="http://www.reddit.com/submit?url=<?php echo $this->url; ?>&title=<?php echo $this->title; ?>" rel="nofollow" title="<?php echo $this->lang['share_on_reddit']; ?>" onclick="return shd.open(this.href,855,900);">Reddit</a></li>
<?php endif; ?>
</ul>
</div>
<!-- indexer::continue -->
Simply create your own sharebuttons_default
template under Layout - Templates and overwrite its contents with this one.
Thanks, that's works perfectly!
So do I still have an issue with the website and redirects? This could be a bit of a pain.
I know this isn't related to your module but do you know which line to edit in the htaccess file properly so it doesn't use file extensions?
So do I still have an issue with the website and redirects? This could be a bit of a pain.
Hm, I don't know, I wouldn't worry about it for now. Just look out for any issues, where parts of Contao are not behaving as they should (modules with redirects or something).
I know this isn't related to your module but do you know which line to edit in the htaccess file properly so it doesn't use file extensions?
Just replace
RewriteRule .*\.html$ index.php [L]
with
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
(and also remove the URL suffix from the system settings in Contao)
Thanks, that's pretty much what I did before. Thanks for all you help.
I'm having a problem with the Twitter and Facebook link. the links don't seem to be adding the social media sites address before the link so when you click it it launches a new window but it loads my website page not found page in the window. could this be because it's on a sub domain? here is a link: http://belviso.360fusionhosting.co.uk/blog/id-2015-dates-for-ipaf-3a-and-3b-training All the other share links work fine.