Exempt Facebook Crawler from .htaccess redirect - facebook

We recently forced all pages to be HTTPS through .htaccess:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
The problem is that I get "Circular redirect path detected" from Facebook debugger because the original URL is https, but the og:url is http (so we don't lose all of our old likes), and then it gets a 302 loop back to https.
How can I make Facebook an exception to this .htaccess rule?

This question addresses the user-agent that facebook external hits will look like. You just need to add a condition to check for it:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Related

Htaccess Redirect To Custom Permalinks from Blogspot to Wordpress

I move from Blogspot to Wordpress.
Blogspot url
domain*com/year/month/post-name.html
Wordpress Set Custom Permalink
domain*com/%author%/%postname%/
I use this redirection on .htaccess
RedirectMatch 301 /([0-9]+)/([0-9]+)/(.*)\.html$ /$3/
RewriteCond %{QUERY_STRING} ^m=1$
RewriteRule (.*) $1? [R=permanent]
Its only redirect to domain*com/%postname%/
How to redirect url to domain*com/%author%/%postname%/

www to non-www for subdomains

I have a domain and two subdomains, each with it's own wordpress installation. I'd like to redirect the www to non-www for domain and the two subdomains. In its current form, my htaccess rules only work for the domain level.
I have these settings in my .htaccess file on domain level:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.electricmura\.ro [NC]
RewriteRule ^(.*)$ http://electricmura.ro/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.electricmura\.ro)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
But this only works for the domain level, not for the two subdomains.
www.electricmura.ro redirects to http://electricmura.ro/
www.mca.electricmura.ro/ gives a "We can't connect to the server" error (Firefox) or "www.mca.electricmura.ro’s server IP address could not be found." (Chrome)

APACHE2: avoid https:// REDIRECT to open phpmyadmin

I have a site https://example.net
to ensure that all users go to the https:// I set up a redirect with APACHE (on the default.conf) as followed:
<VirtualHost *:80>
ServerName example.net
Redirect permanent / https://emalsys.net
# DocumentRoot /var/www/example.net/
<VirtualHost *:80>
My issue is when I try to access my phpmyadmin example.net/phpmyadmin I redirect to https://example.net/phpmyadmin and the page cannot be displayed.
(It is obviously working if I remove the Redirect).
How can I get avoid the redirect only for my phpmyadmin?
Any idea?
This is what I use in my servers to force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
For other examples see Apache's wiki https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
You can enter a REWRITECOND before a rewriterule:
REWRITECOND %{REQUEST_URI} !^http://www.example.com/phpMyAdmin
REWRITERULE / https://emalsys.net
A way around:
I do not know why but if I type as url example.net/phpmyadmin I will be redirected to https://example.netphpmyadmin/ but if I write https://example.net/phpmyadmin/ (with the /)I go to php my admin.
No idea why but I hope it will be of help to others.
to force https:// on pyp myadmin I added: $cfg['ForceSSL'] = true; at the end of phpMyAdmin’s config.inc.php file (see http://thebarton.org/forcing-ssl-with-phpmyadmin/).

Redirect entire request to new domain, without post-pending ANY content after the .com of the original request

I have google'd for at least 3 hours and tried all the examples on stack overflow and other forums.
Does anyone know how to use .htaccess (either redirect or rewrite) to be able to redirect all traffic from one domain to another without passing anything after the .com?
I have an old domain:
http://www.olddomain.com
I want to redirect ALL requests to that domain to a specific URL
http://www.newdomain.com/new/directory/
I have tried quite a few types of redirects and rewrite rules in .htaccess, but if I make a request like:
http://www.olddomain.com/some/directory/
the redirect always comes to the new domain like:
http://www.newdomain.com/new/directory/some/directory/
The redirect is post pending the URI onto the redirect.
I have tried adding ? at the end of the new URL and that does not help.
Here are some of my redirects. (Domain names changed to protect the innocent)
RewriteEngine on
#RewriteRule ^ http://www.newdomain.com/new/directory/ [R=301,L]
#RewriteRule ^ http://www.newdomain.com/new/directory/? [R=301,L]
#RewriteRule /?$ http://www.newdomain.com/new/directory/? [R=301,L]
RewriteRule ^([^/\.]+)/?$ http://www.newdomain.com/new/directory/? [R=301,L]
I tried the Redirect command as well...
Redirect 301 / http://www.newdomain.com/new/directory/?
None of these seems to remove the /some/directory/ and just keep redirecting to
http://www.newdomain.com/new/directory/some/directory/
Any thoughts would be very much appreciated.
Try just:
RedirectMatch 301 ^ http://www.newdomain.com/new/directory/?
But if you would rather use mod_rewrite, it looks like you were pretty close with your rules, it just needs to have the regular expression match anything:
RewriteRule ^ http://www.newdomain.com/new/directory/? [R=301,L]
There's a caveat that if both of these domains are actually hosted on the same server, the same document root, and you're going to be putting this in an htaccess file, then you'll need to add an additional check above the RewriteRule for the host:
RewriteCond %{HTTP_HOST} olddomain.com$ [NC]

how to redirect any url format to my domain?

I have a parkeddomain.com
It used to be a web application but I want any parkeddomain.com url to redirect to another domain
so
parkeddomain.com/signup would lead to anotherdomain.com
parkeddomain.com/page.php?q= would lead to anotherdomain.com
mod_rewrite:
RewriteEngine on
RewriteRule ^.*$ http://anotherdomain.com