Like Button, vBulletin and Mod Rewrite - .htaccess

I'm having a really, really, really weird problem on my vBulletin board using Facebook's Like Button. In my thread template I'm using the following code, which is located inside body tag:
<td class="vbs_forumdata alt1">
<div id="fb-root"></div>
<script type="text/javascript">(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src="//connect.facebook.net/en_US/all.js#xfbml=1";fjs.parentNode.insertBefore(js,fjs)})(document,"script","facebook-jssdk");</script>
<div id="thread_sharing_content_facebook">
<div class="fb-like" data-href="{vb:raw sharingurl}" data-layout="button_count" data-send="false" data-show-faces="false" data-width="90"></div>
</div>
</div>
</td>
As soon as the template is processed by the vBulletin engine, the variable {vb:raw sharingurl} is replaced by the thread's canonical URL, that looks like this:
http://MYDOMAIN/threads/THREADID-THREADTITLE
For example:
http://www.mydomain.com/threads/1-Hello-Community
Looking at the HTML source of a thread page, everything seems to work as intended:
<td class="vbs_forumdata alt1">
<div id="fb-root"></div>
<script type="text/javascript">(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src="//connect.facebook.net/en_US/all.js#xfbml=1";fjs.parentNode.insertBefore(js,fjs)})(document,"script","facebook-jssdk");</script>
<div id="thread_sharing_content_facebook">
<div class="fb-like" data-href="http://www.mydomain.com/threads/1-Hello-Community" data-layout="button_count" data-send="false" data-show-faces="false" data-width="90"></div>
</div>
</div>
</td>
But then, if I click on the Like Button to share the thread page... here comes the drama:
The original URL of the thread page is messed up transformed into something like:
http://MYDOMAIN/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/THREADID-THREADTITLE
Anyone knows why I'm getting that strange problem? The only thing I was thinking about trying to figure it out by myself, is my htaccess file which contains some rewrite rules. It's almost the vBulletin default one... but, anyway, here they are:
RewriteEngine On
RewriteBase /
// Block Bad Bots
RewriteCond %{HTTP_USER_AGENT} [...]
RewriteRule ^.*$ - [F,L]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^forums/.* forumdisplay.php [QSA]
RewriteRule ^members/.* member.php [QSA]
RewriteRule ^threads/.* showthread.php [QSA]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(?:(.*?)(?:/|$))(.*|$)$ $1.php?r=$2 [QSA]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ - [NC,L]
RewriteRule ^(.*)$ - [R=404,L]
EDIT: I tried using the Facebook URL debugger and...
Scrape Information
Response Code: 200
Fetched URL: http://www.mydomain.com/threads/1-Hello-Community
Canonical URL: http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
Critical Errors That Must Be Fixed
Could Not Follow Redirect Path: Using data from http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community because there was an error following the redirect path.
Errors That Must Be Fixed
Too Many Redirects: URL redirected too many times. Please reduce the number of redirects.
Like Button Warnings That Should Be Fixed
Admins And App ID Missing: fb:admins and fb:app_id tags are missing. These tags are necessary for Facebook to render a News Feed story that generates a high click-through rate.
Like Button Tag Missing: og:title is missing. The og:title meta tag is necessary for Facebook to render a News Feed story that generates a high click-through rate.
Like Button Tag Missing: og:type is missing. The og:type meta tag is necessary for Facebook to render a News Feed story that generates a high click-through rate.
Like Button Tag Missing: og:image is missing. The og:image meta tag is necessary for Facebook to render a News Feed story that generates a high click-through rate.
Open Graph Warnings That Should Be Fixed
Inferred Property: The 'og:url' property should be explicitly provided, even if a value can be inferred from other tags.
Inferred Property: The 'og:title' property should be explicitly provided, even if a value can be inferred from other tags.
Inferred Property: The 'og:description' property should be explicitly provided, even if a value can be inferred from other tags.
Inferred Property: The 'og:image' property should be explicitly provided, even if a value can be inferred from other tags.
Object Properties
og:url: http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
og:type: website
og:title: #Page Title#
og:image:
og:description: #Meta Description#
og:updated_time: 1348134967
Redirect Path
originale: http://www.mydomain.com/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
rel="canonical": http://www.mydomain.com/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/threads/1-Hello-Community
Final URL is in bold (this is the URL we tried to extract metadata from).
Please, please, PLEASE... help me out!

You may need to add the meta og tag
<meta type="og:url" content="<?php get_current_url(); ?>" >
try it

Related

Format url to friendly url using .htaccess

I try to format my url to friendly url by using htaccess
This is my url
http://localhost/index.php?go=product&id=32
I'm using REQUEST METHOD
$id = $_REQUEST['id'];
//Do some thing with php code to get info product from Mysql
$Title = $row['title'];
//Example: Computer 4GB 2CPU
But when I want to SEO my website, it's not good, I wish my url like this:
http://localhost/product/32/Computer-4GB-2CPU
So in your .htaccess, add this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ index.php?go=$1&id=$2&product=$3 [NC,L]
In your <head> add the following:
<base href="/">
So that the images and CSS work.
Add a get method for product to get the name, it should work, if it doesn't go ahead and comment.

Refresh page on apache with React doesn't work

I'm trying to use React to create a SPA, but I'm running into problem when trying to reload the page.
Before I continue, I must say I already read these questions this and this. I manageg to made it work, but only for the first url.
For example, I have a blog page containing all the posts, accessed via this url mysite.com/blog. This one works fine, if I refresh the page, everything reloads again.
However, when I try to access a single post using a dynamic url, then the page doesn't work. For example, I have this router setup:
// Definiton
<Route path="/post/:url" component={Post} />
// Link
<NavLink to={"post/" + post.url}>...</NavLink>
// Url on the browser
mysite.com/post/this-is-my-first-post
In this case, it's not working. This is my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
After looking more at the problem, I noticed it's trying to load the main files from a different location. For example, when I'm on the page mysite.com/blog it's loading the .css and .js files from mysite.com.
But when I'm the page mysite.com/post/this-is-my-first-post and I refresh the page, it's trying to load the .css and .js files from the directory mysite.com/blog.
I did what Stuffix told in the answe, to check the url definition and also the config at my apache, but everything is enabled and working, just like the answer says.
Well, after looking at some other projects I have using Angular, I noticed one thing, and it was easier than I tought.
Just had to add the tag base on the head of my index.html.
<base href="/" />
This htaccess worked for me with react and angular
<IfModule mod_rewrite.c>
RewriteEngine on
# -- REDIRECTION to https (optional):
# If you need this, uncomment the next two commands
# RewriteCond %{HTTPS} !on
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# --
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]
</IfModule>
In your <Route />, you're declaring the post route is /post/this-is-my-first-post which is correct.
But in your <NavLink />, you're pointing towards /blog/post/this-is-my-first-post since you've missed a slash.
<NavLink to={"post/" + post.url}>...</NavLink>
| here
Thus leading to a 404.
If this doesn't help, your snippet looks fine so the problem might be on what does post.url returns.
Also, your .htaccess looks fine so I would say you might have missed something in your Apache config like AllowOverride all. See this answer.

Reviews in Magento don't work after changing .htaccess

I need help. My store is running on Magento CE 1.9 and I wanted either add trailing slash to all my urls in Magento, or to get rid of it. Adding trailing slash didn't work, because some images and other linked files didn't want to load, so I added this in my .htaccess file, to get rid of trailing slash:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L,NE]
The slash disappeared, and the website was rendering correctly. However, now I noticed that reviews of my products don't get registered at all. The customer can click on the link to write a review, however, after clicking submit button the page refreshes, but there is no message that the reviews is successfully submitted. The reviews also doesn't get registered in the admin panel.
Maybe some other modules don't work as well, but I still didn't notice.
This is how the link looks without the code above:
http://xxxxxxx.com/review/product/list/id/1/category/3#review-form
And this is how the link looks with the code above:
http://xxxxxxx.com/review/product/list/id/1/category/3#review-form
Hope this work,
try this rule instead
RewriteCond %{REQUEST_URI} !\.(php|phtml|html?|ico|pdf|flv|jpg|jpeg|png|gif|svg|js|css|swf|otf|woff|ttf|eot|xml|GIF|sql)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
This will add trailing slash to all url if the condition is meet.
Note :
this will redirect the ajax url in onepage checkout also, so if you are using SSL in onepage checkout, add slash manually to all request url, or else this will cause error
go to your frontend//default/template/review/form.phtml file and add
<?php echo $this->getBlockHtml('formkey'); ?> just after the <form> tag if it is not present there

Rewrite resource URL to serve files from subdirectory

I have a static HTML site that uses resource tags (images, css, scripts) as follows:
<html>
<head><title>htaccess test page</title></head>
<body>
<img src="/img/img.jpg" alt="...">
</body>
</html>
When I load the html file in the browser, the request is made to:
http://localhost/img/img.jpg (which understandably returns a 404)
Where as I'd like the request to be made to:
http://localhost/site/img/img.jpg
The directory structure is as follows:
- www
- site
- .htaccess
- img
- img.jpg
I have been searching for a solution and have a vague idea that RewriteCond is the way to go, but I can't get this to work:
RewriteEngine On
# if requested URI is not a file
RewriteCond %{REQUEST_FILENAME} !-f
# serve the file from the img directory, yes, very limited,
# and requires me to add rules for scripts, css etc.
RewriteRule ^(.*)$ img/$1 [L]
Any help will be highly appreciated. SO returns quite a few solutions to this issue but none of them seem to work.
You solution is going to treat every file in this way and will re rout it. With this RewriteRule only images will be redirected to /site/{Path of the image defined in HTML}
RewriteRule ([^.]+\.(jpe?g|gif|bmp|png))$ /site/$1 [R=301,L,NC]
You should put images like this <img src="img/img.jpg" alt="...">
The final version looks like this:
RewriteEngine On
# if requested URI is not a file
RewriteCond %{REQUEST_FILENAME} !-f
# image part
RewriteRule ([^.]+\.(jpe?g|gif|bmp|png))$ /site/$1 [R=301,L,NC]

Rewrite Rule causes "partially encrypted connection" in Firefox & Chrome

The question is based on the question htaccess rewriterule: redirect http to https or https to http (both ways) depending on URL typed. The great solution (thanks to Ulrich Palha) looks like this:
RewriteEngine on
RewriteBase /
#determine if page is supposed to be http
#if it has p=home or p=home1 or qqq=home in querystring
RewriteCond %{QUERY_STRING} (^|&)(p=home1?|qqq=home)(&|$) [NC,OR]
#or if query string is empty
RewriteCond %{QUERY_STRING} ^$
#set env var to 1
RewriteRule ^ - [E=IS_HTTP:1]
#all pages that are supposed to be http redirected if https
RewriteCond %{HTTPS} on
RewriteCond %{ENV:IS_HTTP} 1
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
#all other pages are sent to https if not already so
RewriteCond %{HTTPS} off
RewriteCond %{ENV:IS_HTTP} !1
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
Unfortunately, once I add this code to .htaccess file, everything works fine, but https started look broken, if contains links to css or pictures from the server, although the paths are relative.
The page below (https://www.example.com/?p=welcome) displayed with a broken SSL connection, FF browser says "Your connection to this site is only partrially encrypted"
<head>
<title>ddd</title>
</head>
<body>
Hello
<img src="/gfx/stars/help.gif" alt="" />
</body>
</html>
Why?
Once I remove <img src="/gfx/stars/help.gif" alt="" /> from the page , FF displays https fine, the URL bar is green then (SSL certificate is displayed). The same error appears, when I test it using Google Chrome.
So, what's wrong with <img src="/gfx/stars/help.gif" alt="" />? The path is relative.
The same happens if I add
<link rel="stylesheet" type="text/css" href="/css/mycss.css" />
Once the page has loaded and the browser starts requesting images and so on, over https. By my reading of your rewrite rules, because the path to the image has no query string IS_HTTP is set to 1. This then causes your rewrite rules to do a redirect to the http version of the image URL which is why the browser complains
One way to fix this is to avoid processing resources (since you don't have any special rules for them anyway) as follows
RewriteEngine on
RewriteBase /
#if its a resource (add others that are missing)
RewriteCond %{REQUEST_URI} \.(gif|css|png|js|jpe?g)$ [NC]
#do nothing
RewriteRule ^ - [L]
#rest of existing rules go here

Resources