I have a simple rewrite rule that writes to an external domain using the Helicon Isapi_Rewrite 3 RewriteProxy derictive.
Example: RewriteProxy blog http://blog.com
However, links on the external site are not masked by the proxy as I would have expected them to be. They are still pointing to http://blog.com/link1 rather than http://mysite/blog/link1.
Could anyone point me in the right direction of a solution to this?
Thanks
This discussion on the Helicon Tech forums addresses the same issue.
http://www.helicontech.com/forum/8460-rewrite_proxy_to_2d_machine.html
The first example provides code for ISAPI Rewrite 2, but the thread includes ISAPI Rewrite 3 syntax further down the page. Here's an adaptation of their version 3 code for your example.
RewriteEngine on
RewriteBase /
RewriteRule ^blog$ http://mysite/blog/ [NC,R=301]
RewriteProxy ^/blog(/.*)?$ http\://blog.com$1 [NC,U]
(This is untested because I am running ISAPI Rewrite 2.) Note that I hit some snags when attempting to reverse proxy another site under my "main" domain. You might discover these issues as well.
1) Non-Relative Links
Unless the application has been coded from the ground up to assume reverse proxying, I found it likely to break. A bare-bones HTML page using all relative links like will work. However, serving HTML through a reverse proxy that contains this code will map to http://mysite/page_from_the_root.html. ISAPI Rewrite does not know to intercept that request, but it would proxy content if the user's browser hit http://mysite/blog/page_from_the_root.html
2) Cookies
Blog.com might write cookies from the blog.com domain. A page served through the MySite domain might not be able to access these cookies, depending on the user's browser settings.
3) JavaScript and AJAX
4) SSL Certificates
Related
After I have upgraded my site I see that once I go live with new version some parts of the website URLs will not be redirected for gallery, blogs and files because of new structure. And there is no way fixing it within the CMS. So my goal is to use NGINX redirects.
I wonder do any of you know any NGINX rewrite tricks to make such redirects possible?
website.com/forums/blogs/ into website.com/blogs/
website.com/forums/gallery/ into website.com/gallery/
website.com/forums/files/ into website.com/files/
I actually need the part forums dropped from the URL only and ONLY when the address is going for forums+blogs/gallery/files. Don't want to loose that google traffic.
So for example
website.com/forums/blogs/entry123/my-dog/ is redirected to
website.com/blogs/entry123/my-dog/
BUT
website.com/forums/topic/my-dog/
is left alone and working just like before because the following subfolder is neither blogs or gallery or files.
I needed that once on Apache and this one worked but on Nginx I have no idea.
RewriteRule ^forums/(blogs|gallery|files)/(.*)$ /$1/$2 [L,R=301]
You can try something like
rewrite ^/forums/(blogs|gallery|files)/(.*)$ /$1/$2;
Please note that rewrite directive accepts some flags wich meaning depends on where is it placed (is it inside a server or location block). Detailed documentation is here.
Suppose i have
3 php pages
www.example.com/page1.php?var1=data1&var2=data2&var3=data3
www.example.com/page2.php?var1=data1&var2=data2&var3=data3
www.example.com/page3.php?var1=data1&var2=data2&var3=data3
For good SEO . I need URL like
www.example.com/page1/data1-data2-data3
www.example.com/page2/data1-data2-data3
www.example.com/page3/data1-data2-data3
i need all the variables for proper functioning of php pages. Some suggests me to use htaccess file but my website is on godaddy windows hosting so htaccess doesn't work ..
.
Go Daddy allows you to use URL rewrite module if you are on windows hosting plan. You can achieve the desired effect with URL routing.
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module should give you all the information you need for setting up the appropriate rewrite rule.
I am trying to enforce SSL on a folder (blog admin). That part is fine - all pages are SSL, but the site is generating error messages for insecure contents on the page. I can go after all those links individually, to enforce SSL on the links.
I was wondering if that could be done through htaccess alone?
This is what I have done for SSL enforcing on the admin folder:
#forcing https for admin folder
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} admin
RewriteRule ^(.*)$ https://mysite.com/blog/admin/$1 [R,L]
How can I convert all the non ssl links to ssl on the same page ?
Addition:
1) I am using wordpress 3.6 with different plugins that come along with it. Only the admin areas is SSL, and the rest of it, other than login page (that is outside of admin is also SSL) are non SSL (for example the Blog feed for the end users).
2) A few of insecure contents are coming from my own site, but then there are others which are coming from the plugins I am using. For example disqus commenting system, and flickr.
3) I can force the internal links for images, css, and jscript by simply using 'setting for permalink' on wordpress (noticed the url was provided as http and not https). Similarly, I can locate and fix the other links like this one:
The page at https://mysite.com/blog/wp-login.php ran insecure content
from
http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js?ver=3.6
4) The issue is:
If I use permalink setting, then the blog links are created as https
instead of http, and that breaks the plugins I am using for the non
SSL pages, for example disqus comment feed don't show up on the blog
page. Secondly, The painful process of fixing all the non ssl links.
Also, I can always miss out on some of them, since I am doing it
manually. It would be really helpful, if I could enforce SSL for all
these non SSL links using htaccess, perhaps the only easy solution.
Rewrite rules (which are in in fact redirections, when it's about HTTP to HTTPS) won't help, since by the time the initial plain HTTP request reaches the server, it's too late.
It's the links on the page you serve that must be addressed. This is generally up to the application (e.g. your PHP/CGI applcation) running on the server, not up to the server itself. The server would need to be able to process the content of the responses it sends to replace these links, not just redirect the requests (like mod_rewrite does).
mod_proxy_html (distributed with Apache 2.4 or separately in earlier versions) is a module that can to in-depth processing of the response, but I'm not sure whether it can be used as a post-processing tool for PHP running on the same server, to rewrite the links it sends.
Of course, this won't fix links to external resources that are not available via https:// anyway.
I have a server. Lets call it http://A.com
I also have an 'Enjin' forum board. Lets call it http://A.B.com.
The server is useful for many scripts and functional components for the admins. The forum boards are for the community, but I can only add HTML modules to it. No custom scripting.
Currently, I have it set up to redirect the index of http://A.com to http://A.B.com using HTML redirection, and so those who navigate to the root of A.com will be sent to the forums.
I would like to make it so if you navigate to http://A.com, it'll show the contents of http://A.B.com. We once used an iFrame, but that had a detrimental affect on the forums, so currently we just redirect them. I've seen someone using the same system have a URL such as http://C.com/forums/viewforum/212877 showing the contents of http://C.B.com/forums/viewforum/212877
I assume mod_rewrite could be capable of this, but how exactly?
It sounds like you want to set up a reverse proxy wherein a client requests a page from http://A.com/ retrieves the page from http://A.B.com/ using HTTP, and then returns that content as it own response to the client.
See http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxyvia
"A reverse proxy is activated using the ProxyPass directive or the [P] flag to the RewriteRule directive. It is not necessary to turn ProxyRequests on in order to configure a reverse proxy."
You would need to check what happens regarding links on pages. If http://A.B.com/ uses absolute links then they will be to pages inside http://A.B.com/ . But relative links will still be under http://A.com/ .
i have a site like twitter.com on server one and on server two i have forum, which path is like domain.com/forum
on server one i wanted to implement wild card dns and put main domain on it. but on server two i wanted to keep forum separate, i cant give sub-domain forum.domain.com, because all its links are already put in search engines and link back to domain.com/forum.
so i was wondering, how can i put domain and wild card dns on server one and still able to give path on server 2 for domain.com/forum (as sub-folder).
any ideas?
do you think htaccess can do that job? if yes, then how?
You could use htaccess and mod_rewrite so domain.com/forum actually displays pages from forum.domain.com.
Maybe something like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule domain.com/forum/(.+) forum.domain.com/$1
Easy - use a proxy! If you like apache you will love apache mod_proxy for your purpose.
<VirtualHost *:80>
ServerName maindomain.com
ServerAlias *.maindomain.com
# insert document root and general settings for this domain here
# ...
ProxyPass /forum http://forumdomain.com
ProxyPassReverse /forum http://forumdomain.com
ProxyPassReverseCookieDomain forumdomain.com maindomain.com
</VirtualHost>
This configuration makes apache do a HTTP-request to your internal domain (forumdomain.com) without notifiying the users browser of the internal location. Your Forum will be accessable at http://*.yourdomain.com/forum. Cookies and headers the forum sents will get rewritten accordingly and Search-engines will not take notice of your backend-server.
You can read more about it at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
Should you need to rewrite reference sin your html (href, src ...) you might google on "mod_proxy_html".
A solution like this could of course be build with other intelligent proxyservers like squid as well. You can use it to map any content from "backend servers" to your public domain.
Make sure routing is OK or set up a host-entry for your internal domain (forumdomain) with a internet ip-addresse 192.168 ...
Enjoy your site and give feedback how worked out :)
p.s.: a "RewriteRule" directive can potentially do the same thing for you but the rdirect will be visible (and executed) by the client unless you specify the "P", foricng it to do an internal proxy request. If available I would prefer the mod_proxy though as it is more versatile and allows for more configuration.
If you use a proxy on server 1 pointing to server2, you will increase the load on server 1, since all traffic will be routed through it. Besides, if server 1 goes down, nobody will be able to reach server 2 either. Of course it is possible though, but these things are to be considered.
I would suggest setting up a supdomain for server 2 anyway, like forum.domain.com, and on server 1 you set up a 301 redirect from domain.com/forum to forum.domain.com using mod_rewrite from htaccess. Using that technique, you can even redirect calls to specific links to their corresponding page on server 2. Search engines will follow the 301 and they will eventually update the index.
You can use a 301 redirect to make sure the search engine update their index with your new urls like so:
RewriteRule domain.com/forum/(.*) http://forum.domain.com/$1 [R=301,L]
If you've got two servers you don't really have much choice but to use a redirect (ideally a 301 Permanent redirect) to move users from domain.com/forum to forum.domain.com.
The only other way to do it would be to put a reverse proxy in front of those two servers, which reads the URL and internally directs the query to the right server, but that's then an extra piece of hardware.