Its possible to set a domain easily for a internal page of a CMS like WP or Joomla on a LAMP environment? - wordpress

Lets say for example that I have a CMS installed on a domain: mycms.com
With Joomla or Wordpress on a LAMP environment (Linux, Apache, Mysql, PHP), lets say that it uses Cpanel.
And I have a page like for example mycms.com/mycategory wich links for different internal post/articles.
mycms.com/mycategory/post-1
mycms.com/mycategory/post-2
Now I have another domain: myotherdomain.com
And I want to setup this domain for that page (mycms.com/mycategory) In a way that every internal page also responds to that, example:
myotherdomain.com/post-1
myotherdomain.com/post-2
Notice, its not a simple redirect using PHP header() or JS, I want that myotherdomain.com to stay visible on browser address.
My question, this is possible? And its possible to do this without a dedicated server with SSH access? How I may do this? Editing my .htaccess?

Yes, you can. As you say, it's not a simple redirect, but it's a Proxy redirect. You can solve such problems at any preceding reverse proxy or immediately in Apache with mod_rewrite's proxy flag (it is [P]).
If you don't need any special pattern matching, you can even use PorxyPass:
ProxyPass "/post/" "https://mycms.com/mycategory/post/"

Related

How to use another domain for a specific url?

I'm building a WordPress website for a client and can't figure out what to do here. I'm using translatepress to make my website multilingual and the client wants to have another domain for different language. So the default domain is example.com but English version is example.com/en . Is it possible to add another domain which replaces example.com/en and is still functional by pressing all the links? So it's like example2.com points to example.com/en , but not as a url forwarding, but it replaces the whole example.com/en part completely. What are my options here? Thanks.
You can have different sites in a network on different domains. It is just on the other domain, not on both. Since WP stores internal links as absolute URLS, you need to create the sites on the correct domain from the start, or use wp-cli or similar to re-write existing links when you change.
I was about to recommend the plugin I have used, but see from https://wordpress.org/support/article/wordpress-multisite-domain-mapping/ that from 4.5 it's a WP native feature!
Note: i don't use translatepress but have different languages as different sites in a network. Since you talk about sub-domains I'm assuming you do something similar

How to proxy a rails app in heroku with a WP blog under same domain

I have this:
A rails app on Heroku that servers mydomain.com
A WP site on another hosting (that I can move to AWS .. or even heroku)
I need that mydomain.com/blog serves the WP installation, I DONT want it to be a subdomain for SEO.
My first idea was setup apache / nginx as reverse proxy on a instance on AWS. However I worried that this setup is not optimal as backends are in different services.
It's possible to setup heroku dyno as a proxy? I understand there is no way to modify the system files on heroku, like create a custom nginx setup to do the proxy. I was wondering if there is some application that works as a proxy and can be installed in heroku, next setup the blog in heroku also.
Or it's a good idea to setup an AWS instance as proxy in the same region that the heroku is (us-west1), and setup the blog also there.
I'm interested in the pros and cons of each solution and what would be the best way to go.
I had tackled the same exact problem with Rails and WP for quite some time.
My configuration and result:
Rails app is hosted on heroku (www.sexycrets.com)
WP Blog is hosted on another server (blog.sexycrets.com)
When the browser requests www.sexycrets.com/blog he receives the same html page that he would have received if browsing blog.sexycrets.com and the url on the browser remains the same
How I achieved it
One solution that does works well for SEO is to use a gem as reverse proxy (I use drewwed/rack-reverse-proxy from Github). You can configure it to intercept the route "/blog" (and "/blog/") so that every time Rails is asked for /blog it loads your WP site with a backend call and returns it to the user. This is a completely transparent operation from the user browser perspective, aside from the delay introduced. The user browser has no way to know that the blog page returned in the response was loaded from another server, the url on the browser remains "www.sexycrets.com/blog".
Pros: SEO requirements are satisfied
Cons: Performance since the reverse proxy is not very performant in terms of delay introduced
Alternative
For sake of completeness the other option I tried was to use an iFrame in a static page hosted on heroku that loads the WP. The problem is that in order for it to work avoiding a circular reference all the links in the WP blog have to point to blog.sexycret.com (not www.sexycrets.com/blog) which partly defeats the SEO purpose.
Pros: Performance is very good since it is not even using Rails: the user browser loads the static /public/blog/index.html page that contains just the iFrame that points to the WP blog
Cons: the links in the blog are not pointing to the main domain but to the 3rd level domain defeating
Hope this helps!

Pointing domain at seperate sub-domain & domain

I have a domain residing with one organisation for managing DNS and a wordpress site built as a sub-domain of another site of mine.
I set up web forwarding, expecting the domain to be reflected in the address bar for site visitors, but the sub-domain is showing instead.
i.e. www.domain1.com should forward to subdomain.domain2.com and show www.domain1.com in the address bar. Meanwhile, my www.domain2.com should still render the other wordpress site I have there.
Am I right in thinking I need to do this through my htaccess file? If so, can anyone advise on the syntax I need to use to do this? I can currently only find information on mapping a sub-domain to the www of the same domain.
Thanks in advance :-)
This comes down to the provider's definition of "web forwarding", which is a vague marketing term. It sounds like they're just doing a straight redirection unfortunately, which no amount of playing with .htaccess files can fix: you simply cannot make a website tell the browser to stick another domain name in its address bar.
What I'd suggest is talking to them and see if they can do a CNAME for www.domain1.com to subdomain.domain2.com, or switch to it using the same IP address instead. You will then need to set up your Wordpress install to respond to "www.domain1.com" requests.
do you have control panel for your domains?
Im using direct admin and they call it "domain pointers" - I believe it does exactly what you need.
You need to create alias for your subdomain.domain2.com which will point (not forward, if you forward it also url in browsers address bar will be changed) www.domain1.com to the subdomain.domain2.com without url change.
If you are not using any control panel, you need to create alias manually by adding same dns for your www.domain1.com (no matter A or CNAME) as it is for subdomain.domain2.com AND in server configuration set response for www.domain1.com (ie. apache servername and serveralias, in iis binding)
I dont think .htaccess is a good idea for achieving what you described.

SSL and relative URLs in site links and redirections

I have been working on a website in beta phase for some time now, and am finally about to launch it. There are several links, anchor tags, with relative URLs throughout the site that link to the admin and cart sections of the website, and now they have to be SSL secured.
Also, same question for relative URLs in Response.Redirect("~/../..");
When a user is browsing over http, is there anyway to redirect them to a page with https connection using a relative URL? It seems like poor practice to code absolute URLs for links and redirections for the purpose of SSL. If the domain name changes, I have to rewrite them all. Plus, if I want them to work on my localhost, I would have to change them every time I upload to server. There must be some solution.
Switching Between HTTP and HTTPS Automatically is a very good code to use for the implementation of switching logic fast and easy - and not change your existing code.
Similar: Preparing my ASP.NET / MVC site to use SSL?
These helper methods by Rick Strahl will help you
http://www.west-wind.com/weblog/posts/2007/Sep/18/ResolveUrl-without-Page
Pay special attention to ResolveServerUrl.
Depending on what version of IIS you are running, you could always offload this functionality to the webserver. Check out the URL Rewrite module here.

Host blog on different server?

Currently I have my companies blog on the same server as our main web app - as in example.com/blog
What would be the easiest way to move the blog to a different server yet still let users either access the blog at example.com/blog or blog.example.com?
Issue 301 HTTP redirects from website.com/blog to blog.website.com
The specifics depend on the server.
The answer that I provide is assuming that you are using Apache as the webserver as this is what I am familiar with. If you are using IIS then you may be able to find a similar solution but I cannot guarantee this.
In the past I have come across similar issues, whereby a client is hosting their main website at www.mydomain.com but their blog is hosted by their marketing guys at blog.mydomain.com. For SEO purposes it ca be beneficial to have the blog appear at www.mydomain.com/blog although this is not physically possible due to the nature of DNS protocols.
The answer is to use an Apache module called mod_proxy which allows you to map the url /blog to a subdomain and this is invisible to the end-user and, more importantly, search engines. CodeHaus have published a good article on Configuring mod_proxy (update 2016: link leading nowhere) and you may like to have a read.
mod_proxy is quite complex and it can take a while to get the settings correct but it is by far the best solution to the problem that you describe.
You can use a simple javascript redirect code such as the one below to redirect the user.
<script type="text/javascript">
<!--
window.location = "http://www.example.com/";
//-->
</script>
Are you hosting these servers in your own data center, or are you purchasing hosting? Our corporate site is hosted on multiple servers in our data center. We use load balancers to route traffic to different server farms based upon the URL. So
http://www.foo.com/assets/* might route to a farm of Apache HTTP servers that serve nothing but image files while
http://www.foo.com/apps/* might route to a farm of JEE application servers and
http://www.foo.com/services/* might route to a farm of servers especially designed to host web services and
http://www.foo.com/blog/* might route to a farm of servers that handle nothing but WordPress.
Works great... if you have all of this at your disposal. If you don't, then check out mod_proxy like Matt said (which we used before we bought load balancers).
blog.example.com
blog.example.com is easiest, since you can simply point it to a different IP address.
That is not what I want for a project I'm working on.
example.com/blog
Instead I use Apache mod_proxy to point /blog to another server. Apache docs here.
This worked well:
ProxyPass /blog http://blog.example.com/
ProxyPassReverse /blog http://blog.example.com/
But only after the proxy modules were loaded correctly:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_html_module /usr/lib/apache2/modules/mod_proxy_html.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
Notes
Because of CloudFlare I also had to host the blog from a different hostname, not *.example.com.
I added Disallow: / to my blog.example.com/robots.txt. Like this search engines will not start indexing in two locations. And search engines will simply ignore blog/robots.txt.

Resources