Allowing specific files to run over https - regex

I have SSL set up on the server, but I hardly use it for anything, therefore I am simply redirecting all https:// to http:// via .htaccess. Recently I have created small app for my Facebook Fan Page, but run into couple of problems, since Facebook does not allow http:// any longer.
Question:
How can I let one static HTML file to run with https:// leaving the rest of the set up as it is?
What I currently use in my .htaccess is the following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} https [OR]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [QSA,L,NC]
</IfModule>

Yes.
In your first block with all the conditions, add a condition so that your app will be excluded. For instance:
RewriteCond %{REQUEST_URI} !facebook-app\.html [OR]
For your_app_name, enter something specific that would only appear in the url for the App that you want to exclude from the rewrite. It does not matter if that name appears early or late in the url, just substitute it in the condition.

Related

Adding ?nocache=1 to every url (including the assets like stylesheet) behind the scenes using mod rewrite

Alright, this is due to the pain that godaddy gives me by implementing their own caching in a MANAGED WORDPRESS hosting. I looked it up and as it turns out, their flush caching facility is not available to me in the wordpress dashboard as it is a subdirectory /wp/ installation.
Also, there is no setting to enable "development mode" which apparently turns off caching on the godaddy control panel.
But what I would like to do is to apply ?nocache=1 to every URL related to the site (including the assets like style.css) so that I get the non cached version of the files.
For example, if I put
http://example.com/wp/wp-content/themes/example-theme/style.css
in the browser, I get a cached version of the stylesheet which does not reflect the recent one. But if I put..
http://example.com/wp/wp-content/themes/example-theme/style.css?nocache=1
It shows up the most recent one.
Is this possible? If yes, could someone be kind enough to show me how? Perhaps Something like this... (it doesn't work!)..
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (.*) $1?nocache=1 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress
Thanks for your help!
Try these rules to add required query parameter:
RewriteEngine On
RewriteBase /wp/
RewriteCond %{QUERY_STRING} !(^|&)nocache= [NC]
RewriteRule \.(?:jpe?g|ico|gif|bmp|png|tiff|css|js)$ %{REQUEST_URI}?nocache=1 [R=302,L,QSA,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
They offered a code to disable it directly into your wp-config.php file.
Basically just add:
define( 'MWP_OBJECT_CACHE_DISABLED', true);
https://www.godaddy.com/help/object-caching-on-managed-wordpress-41408

force single site to use https, all other http (wordpress)

I found several related questions, but non of theme seem to work, so I have to ask again:
I'm using a wordpress site and I want a single site to use https (/kontakt/). All other sites have to use the http (due to duplicate content and such).
I tried a plugin called Wordpress HTTPS which should do exactly that, but the plugin is outdated (3 years not updated) and also doesn't work as expected.
For this case, I thought about using the .htaccess. These is my htaccess-file:
My URL looks exactly like this: http://www.example.com/kontakt/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
RewriteCond %{HTTPS} off
RewriteRule ^kontakt/$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE,NC]
# change kontaktform
RewriteCond %{HTTPS} off
RewriteRule ^/kontakt https://www.example.com/kontakt/ [R=301,L,QSA]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/kontakt/
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L,QSA]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
This attempt was taken from here:
force one page to use HTTPS and the others to use HTTP with .htaccess
but that didn't do the trick. My problem now is:
a) the site is not redirected to https (I can confirm the htaccess is working, since i can produce 500's on demand)
b) once it is on https://, all other sides stay on that protocol (already in the link-preview)
What I actually want:
IF the site = /kontakt/ --> use https
ELSE use HTTP
Try these rules:
RewriteEngine On
RewriteBase /
# add www if missing in domain name
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,NE,L]
# if http and /kontakt/ then make it https
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /kontakt/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE,NC]
# if https and NOT /kontakt/ then make it http
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !/kontakt/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE,NC]
# default WP rules
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
I used %{THE_REQUEST} variable for this. THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules unlike %{REQUEST_URI} variable.
Clear your browser cache before testing it and also test in Chrome dev tool with caching disabled.

Redirect and Rewrite to remove .html from url

I have a really basic rewrite rule that I've been banging my head against the wall trying to achieve. I have a static HTML site that I want pretty URLs for.
So, I want /something to serve /something.html and I also want to redirect (externally) from /something.html to /something as to not be penalized on SEO for hosting duplicate content.
I don't want to use Multiviews and I don't want to use <rel cannonical="">
This is what I currently have.
RewriteRule ^(.*)\.html$ /$1 [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
It results in an infinite redirect loop.
It seems to me that the first rule keeps matching even after the requested URL doesn't end in .html.
Yes your rules will cause redirect loop due to use of REQUEST_URI (via RewriteRule) which changes after application of a rule.
You can use:
RewriteCond %{THE_REQUEST} \.html [NC]
RewriteRule ^(.*)\.html$ /$1 [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules.

Redirect everything to one file, disallow direct access to PHP files

I'm struggling with creating a set of rules in my .htaccess file, resulting in constant 500 Internal Server Errors instead.
RewriteRule ^(.*)\.php$ /router.php?rq=$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /router.php?rq=$1 [L,QSA]
I want my .htaccess to behave like this:
All requests (except resources, images, CSS, js, etc) should
redirect to /router.php, preserving query strings. I don't need the
REQUEST_URI as a query string as it is available via
$_SERVER['REQUEST_URI'] regardless.
All attempts to access a PHP file directly, for example user enters
"index.php", should also redirect to router.php.
You can use this rule for your routing:
RewriteCond %{REQUEST_URI} !/router\.php [NC]
RewriteRule \.php$ /router.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /router.php [NC,L]

Htaccess redirect https and http and custom url

I am new to htaccess and even though I get the part to have a custom URL, I can't manage to figure out https redirect combined with having a custom URL. All the options I have found online have given me a redirect loop.
So, suppose I have a page called: mysite.com/hello.php and another one called mysite.com/bye.php.
I want mysite.com/hello.php to become mysite.com/one-hello and bye.php to become mysite.com/two-bye. This is how I have it in my htaccess now:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^one-hello$ hello.php
RewriteRule ^two-bye$ bye.php
But now I want hello.php to always show up as https but bye.php to always show up as http. How could I write all of these?
Thanks!
Have your rules like this:
RewriteRule ^one-hello$ hello.php [L]
RewriteRule ^two-bye$ bye.php [L]
RewriteCond %{HTTPS} off
RewriteRule ^hello\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,NC,R]
RewriteCond %{HTTPS} on
RewriteRule ^bye\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,NC,R]