After switching to https://, all of our articles have lost their Facebook "Like" count. So I would like to disable https just for the Content area of our website, which is at /content.php (articles are in the form of content.php?212-My-Article)
My current .htaccess:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
What do I need to add, in order to redirect all content.php* traffic to http (non-secure), even if they type "https"
Thanks!
You can use this code:
RewriteEngine on
# uri is not /content.php
RewriteCond %{REQUEST_URI} !^/content\.php$ [NC]
# https is off
RewriteCond %{HTTPS} off
# redirec to https site
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I found a way to fix this, without making content.php be unsecure. The Facebook "Like" HTML code looks like this:
<fb:like href="https://www.mysite.com/{vb:raw relpath}" font="tahoma" layout="standard" show_faces="false" width="260" action="like" colorscheme="light"></fb:like>
I use vBulletin. I changed it to http, and everything is fine now!
You'll need to make a change to your first rule to exclude content.php. The you simply add a rule for content.php that will do exactly the opposite of your other rule. You can add the [R=301] flag if your rules do what you expect them to do to turn them into permanent redirects. Permanent redirects are cached by the browser and will reduce the amount of requests done to your server. You don't need to use a capturing group for your first rule, and therefore I just used the ^ syntax, which matches every request.
RewriteEngine on
#Turn the entire site into https, except for content.php
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/content\.php$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
#Use http instead for this url
RewriteCond %{HTTPS} on
RewriteCond ^content\.php$ http://%{HTTP_HOST}%{REQUEST_URI}
There is a very easy solution: with the og:url meta tag:
<meta property="og:url" content="http://example.com/old-url" />
You can read more about that into the FAQ section: https://developers.facebook.com/docs/plugins/faqs
The section is called: How do I move a page to a different URL?
Related
I have an alias domain name which I don't want it to load the website.
I only want my alias domain to access if the request URL has a certain string.
Example: www.myalias.com/pass/whatever/here
The string I'm looking at is the "pass" If the request URL has the "pass" there, then allow to access to the website, if not then return 404 error.
The rule will check if the domain name is equal to "myalias.com" then check to see if the string "pass" is exist in the request URL.
How can I write that to a rule in .htaccess ?
Sounds pretty straight forward: you check the http host, the presence of the pass and react as desired:
This denies requests
RewriteEngine on
RewriteCond %{HTTP_HOST} ^alias\.example\.com$
RewriteCond %{REQUEST_URI} !^/pass/
RewriteRule ^ - [F]
That one sends a custom http status (here 403):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^alias\.example\.com$
RewriteCond %{REQUEST_URI} !^/pass/
RewriteRule ^ - [R=403]
Or you can redirect clients to wherever you want:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^alias\.example\.com$
RewriteCond %{REQUEST_URI} !^/pass/
RewriteRule ^ https://example.com/ [R=301]
You obviously need to have the rewriting module loaded inside your http server. Typically such rules should get implemented in the actual http server's host configuration. If you really want to use a distributed configuration file (".htaccess") you need to enable its interpretation first (see the documentation for the AllowOverride directive).
I'm trying to redirect http requests that contain a specific URI to a different domain with a different URI completely. Redirecting the top level domain works but I can't seem to get the URI rules to redirect.
In essence it should act as follows:
If the url request is:
www.example.com/unique-URI
it needs to redirect to:
https://example2.com/anotheruniqueURI
Currently I have this:
RewriteEngine On
#This redirect works successfully
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ http://example2.com/something [R=301,L]
#This attempt to redirect requests with the specific URI does not work.
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_URI} ^/cars-application$ [NC]
RewriteRule ^/(.*)$ https://example2.com/anotherURI/ [R=301,NC,L]
I've tried many different combinations inside my RewriteRule such as explicitly stating the URI like I did in the RewriteCond above but that doesn't work. Using $1 here won't apply since I'm redirecting to a completely different domain and URI. The URI's I am expecting will be unique. Could you guys provide me some pointers. Is my regex correct or is my rewrite rule capture just wrong?
Your rule failed to work due to the leading slash in your RewriteRule's pattern . Remove the slash to fix it.
RewriteRule ^(.*)$ https://example2.com/anotherURI/ [R=301,NC,L]
Assuming you are redirecting from within a virtualhost of the first domain, you may just do the following:
Redirect permanent /unique-URI http://www.domain2.com/newlocation
So I am having issue I want all requests from
https://transfinmedia.com/author?url=akchopra1-A268
to be 301 redirected on
https://transfinmedia.com/author/akchopra1-A268
but when i use
RewriteEngine on
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule ^author(.*) /author/%1 [L,R=301,NC]
requests to
https://transfinmedia.com/author?url=akchopra1-A268 gets redirected on
https://transfinmedia.com/author/akchopra1-A268?url=akchopra1-A268
what am i doing wrong here, completely out of clue.
By default ,mod-rewrite appends old QueryString to the new target url. To discard QueryString ,you need to put a ? (an empty question mark) at the end of the target url.
RewriteEngine on
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule ^author(.*) /author/%1? [L,R=301,NC]
Make sure to clear your browser cache before using this.
change RewriteRule to
RewriteRule ^author\?url=(.*)$ /author/%1 [L,R=301,NC]
Demo
I have trouble getting this to work properly, what I'm trying to do is make
http://subdomain.domain.com redirect to domain.com:8080 while keeping the original url
"subdomain.domain.com"
Code so far:
RewriteEngine on
RewriteCond %{HTTP_HOST} subdomain.domain.com
RewriteRule ^(.*)$ http://%1domain.com:8080$1 [L]
Which does the redirect, but browser url changes to "http://domain.com:8080" which is not what I seek.
Thank you in advance!
For this to happen you need to enable mod_proxy in subdomain\.domain\.com. Once it is enabled try this rule in DocumentRoot/.htaccess of subdomain.domain.com:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.(domain\.com)$
RewriteRule ^ http://%1:8080%{REQUEST_URI} [L,NE,P]
I want to redirect domain1.com to domain2.com in all cases except one particular case:
domain1.com/subfolder/index.php
I want this domain1.com/subfolder/index.php to be intact and not get redirected to domain2.com because I have hundreds of users already bookmarked this page.
But anything and everything besides that domain1.com/subfolder/index.php, I want domain1.com to be redirected to domain2.com
Please help.
Have the following .htaccess in your web root /
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)domain1.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder/index.php$ [NC]
RewriteRule ^(.*)$ http://domain2.com/$1 [R=301,L]
Use just [L] if you want the redirection to be transparent i.e. without letting your visitors know.
Use !^/subfolder/.*$ if you want to stop redirection for the complete folder as well as its contents.
You can use RewriteCond to check to see the requested uri is anything but the one you want to redirect, capture the desired path and then redirect to the second domain.
RewriteCond %{REQUEST_URI} !^/subfolder/index.php$
RewriteRule (.*) http://domain2.com/$1