IIS7: URL Rewrite - can it be used to hide a CDN path? - iis-7

I am using Rackspace Cloud CDN (Limelight CDN) for my website. The URLs of the CDN are in the format
http://cxxxxxx.cdn.cloudfiles.rackspacecloud.com/something.jpg
My domain is mydomain.com.
Can I use IIS URL rewriting to show http://cxxxxxx.cdn.cloudfiles.rackspacecloud.com/something.jpg as http://images.mydomain.com/something.jpg? Or is this impossible without the CDN setup accepting my CNAME?
If so, can you please help create the URL rewrite rule? (Sorry, don't know how to use regular expressions)
Thanks,
WT

You cannot do this with a url rewrite rule, as that happens on your server.
One of the primary advantages of a CDN is to provide many points of access much closer to the user than your server may be. Using a round trip to your server completely destroys this advantage.
You can write a redirect rule to go from somewhere on your site that then sends the browser to the CDN, but the user will see the url of the CDN, (i.e. it won't be hidden).
To do so, consider something like
RewriteEngine On
RewriteRule ^/images/(.*)$ http://...cdn.....com/$1 [L,R=301]
If you're writing in a .htaccess file instead of in the server config file, then drop the first / after the ^.
As you alluded to, if you could get cloudfiles to accept a CNAME that pointed to their hostname, then it would be possible so simply replace your hostname with yours. However, I assume that by asking this question, you've already explored that avenue.

Related

WordPress will not force SSL for the life of me

Hate to complain but I've spent like 2-3 hours working on trying to secure my WordPress site via SSL. I can successfully browse to my site via HTTPS, but I always get mixed content. I've tried several plugins, but there are still resources that are pulling images via HTTP. If I tried to browse to the URLs of those images manually, my web browser actually switches the URL to HTTPS, so I'm not sure why the site loads the images under HTTP but browsing to the images manually forces it over HTTPS. Very Confusing.
I've tried adding this in the .htaccess file of my root directory, so that all requests to the subdirectory /wp-content/ are forced over HTTPS, but it still does not work:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(wp-content/.*)$ https://www.example.com/$1 [R=301,L]
When I add this into the .htaccess file, reload the site, inspect element, I still see numerous links in here with http.
I've also tried HTTPS Easy Redirection, which forces HTTPS on everything but then results in a redirect loop. Still no luck.
Any suggestions would be greatly appreciated. It seems to just be the images.
What you have setup so far works, but does not address the root issue. As a matter of fact the .htaccess redirect is overkill.
Your Wordpress configuration needs to be edited. Go to your settings>general, ensure that the Wordpress Address Url and Site Address Url are https. It's that simple. You also need to edit any hard coded content urls to https.
You could use some wacky plugin to mutate your links but I would not advise it. But it won't work all the time. That will depend on how your content is constructed.
If you want to play it safe, whenever your add a resource link to content simply omit the protocol like this: ://example.com/.... That scenario works well with content generated by Visual Composer and the likes.
If the SSL is successfully installed in your server then use this plgin: https://wordpress.org/plugins/really-simple-ssl/
This will works for you...
Note: Take backup of your website and database first then proceed with the above plugin.
Thanks

Replace all URL's for my WordPress site using a different domain name?

The domain names used are only examples, so if you could use those example names in your answer that would be great. I'm having a very hard time wording exactly what I'm trying to do and because of that can't find the answer via searching, so I'm posting it as this analogy:
I work for a company that makes WordPress sites. We'll call that company SuperMedia, and their main website is supermedia.com. SuperMedia wants to host their clients' sites on their own server via subfolders. So in this case, we've created a client's WordPress site in the directory http://supermedia.com/greatclient/
The issue is that our client has a domain name, friendlyclient.com, and we need to link this domain name to their site which we are hosting on our server, but we don't want the urls to show "supermedia" at all.
So in simplest terms, right now all of our page urls look like this:
http://supermedia.com/greatclient/about
http://supermedia.com/greatclient/our-services
http://supermedia.com/greatclient/gallery
(etc...)
But we want them all to say:
http://friendlyclient.com/about
http://friendlyclient.com/our-services
http://friendlyclient.com/gallery
(etc...)
but still display the information on http://supermedia.com/greatclient/about, http://supermedia.com/greatclient/our-services, http://supermedia.com/greatclient/gallery, etc. respectively.
Is there a simple, fairly fast way to do this for all the pages we've created, either using .htaccess or some kind of plugin? I don't have a lot of back-end programming/database knowledge, so if it involves advanced programming, could you lay-out some steps on how I can achieve this?
If you are using apache, you can use mod_rewrite to do the rewriting. Try adding this to your .htaccess file(In the friendlyclient.com root folder)
# Match the host
RewriteCond %{HTTP_HOST} ^([^\.]+)\.com$ [NC]
# proxy the entire request to the /host/ and path
RewriteRule ^(.*)$ http://www.supermedia.com/%1/$1 [L,P]
This will make it so requesting http://friendly.com/about will serve http://www.supermedia.com/friendlyclient/about and dont forget to rename ur folder, from greatclient to friedlyclient

ASP.NET Url Rewrite Subdomain Wordpress II7 Web.Config

I have a server that host a variety of asp.net sites on a IIS7 server.
A few of those sites have wordpress blogs in a folder called blog (which is obviously written in PHP). Due to security issues, we need to move those wordpress blogs to a linux server.
So instead of http://www.domainname.com/blog we now have http://blog.domainname.com/ which has the blog url.
The only problem is, due to SEO reasons, we need the blog to be on the same domain as the main site (which is written in ASP.NET).
My question is, is there a way to do a url rewrite so that if someone types in a wordpress link, similar to this:
http://www.domainname.com/blog/index.php/archives/category/mycategory
Can I use a web config URL rewrite to have the above typed in URL actually point to
http://blog.domainname.com/index.php/archives/category/banking
I can't do any sort of redirect. It has to be a rewrite, I've tried righting one myself but have been unable to. The subdomain is the part of the rewrite I can't get past.
Has anyone tried to do this before?
Is there some better way I go about this if not.
Keep in mind the blog and the asp.net site cannot be on the same server due to security reasons, but they must keep the same domain name.
You can't just do a rewrite as the URL you want to rewrite to is on another domain / website. Rewrites only work on the same website.
You have to setup IIS as a reverse proxy server with the ARR module. In combination with the URL rewrite module you will be able to invisibly forward all requests for http://www.domainname.com/blog/* to http://blog.domainname.com/*.
Also note that you will have to setup outbound rewriting in order to change back the URL's that are generated by Wordpress (from http://blog.domainname.com/* back to http://www.domainname.com/blog/*).
See for an example this tutorial: Reverse Proxy with URL Rewrite v2 and Application Request Routing.

How to host a wordpress blog from a domain pointed to an app hosted with google app engine?

I have a Python web app hosted with Google App Engine with a .com pointed towards the App Engine app. I would like to start a Wordpress blog at mydomain.com/blog.
Since Wordpress runs on PHP, I reckon it would be easier to host the Wordpress blog on my other web host account with cpanel and change some domain pointer. What is the best way to achieve this?
I suppose setting a DNS A Name record for 'blog' to point to my other web host account will create blog.mydomain.com and solve this. But is there a way to have mydomain.com/blog pointed to the other web hosting account with the Wordpress blog? Thank you.
Another approach similar to renab's: on your Wordpress box you can configure the Apache (or any other sensible http server) to work as a proxy in front of your App Engine application for every URL but the /blog one (which would be served directly).
You could also enable some level of caching on the Apache server and save a little on processing costs.
A simple solution may be to create the A record you mentioned in your question then put an index.html in the blog/ directory on app engine that contains
window.location = "http://blog.mydomain.com"
as the onload function of the body tag.
Another solution is adding a .htaccess file which redirects http://www.mydomain.com/blog to http://blog.mydomain.com.
Edit: As mentioned in the comment below, appengine does not support this method. I am leaving it in for the off chance that it will help someone who has a similar question not related to app engine.
A similar redirect would be needed for the domain without www in front of it.
Edit for better htaccess example:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
RewriteRule ^blog/(.*) http://blog.mydomain.com/$1 [R=301,L]
You will have to check my htaccess syntax, its been a while since I had to write rewrite rules, and I don't have a webserver handy to test it

Using HTTPS instead of HTTP

I have a website that user have to loggin to. I want to use HTTPS so make a secure encrypted connection to the server to check the user name and password.
Currently on my server i have a folder called httpdocs, this is where my website is store, i also have a folder called httpsdocs.
Now as i stated my website is stored in httpdocs so logically i would go to http://website.com
But i found that if i go to https://website.com i get a secure connect to the pages stored in httpdocs.
Anyway, my question is, whenever i go to another link i loose the secure connect (URL goes back to http://) So how do i keep it all secure? Would i have to use the full URL in the href because that seems a bit lame instead of just using href=page2.php .
I'm new this area of website developing, but i am experienced in developing if that helps you.
Thanks a bunch for the help.
Some basic tutorials or reading material would be awesome if anyone knows of anything good?
Thanks again.
To answer your question in the comments you should use mod_rewrite (assuming its enabled):
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
that will send any webpage to https.
Do not use http://foo.com/path in urls, use //foo.com/path instead (or, even better, if you stay on the same server, use /path - it surely works). Doing full urls is bringing redundancy and brittleness. Avoid it.
Check out HTTP Strict Transport Security (HSTS):
https://www.owasp.org/index.php/HTTP_Strict_Transport_Security
Basically, you can force the browser (unless it's IE<12) to always use HTTPS by adding this header to the secure site's configuration:
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains"
This can also be combined with a 301 (PERMANENT) redirect for the non-secure/HTTP site's configuration, also outlined on the above referenced site.
Additionally/Alternatively, you can set the base href on your "website.com" pages by adding something like this towards the top of the <head> tag:
<base href="https://website.com/">
This will set all relative urls on the page (including links, stylesheets, scripts, images, etc.) to use the HTTPS site's root as their base. Depending upon the structure and size of your site, however, you will want to verify for each page that its base href and/or the urls within the page include any necessary path information (i.e. subdirectories). Otherwise a link on http://website.com/some/directory/page.html that points to "otherpage.html" will direct to http://website.com/otherpage.html instead of http://website.com/some/directory/otherpage.html . In such cases you would want either a base href of "http://website.com/some/directory/" or the relative url in the link should point to either "/some/directory/page.html" or "some/directory/page.html" (no slash needed in this case).

Resources