How to load wordpress by two URL - wordpress

I need to wordpress from 2 url, my main wp already run in subdomain wp.domain.com but I can't access from domain.com/wp, I try some change in database and .httaccess file, but I can't run it with 2 url
I need can access both of them :
wp.domain.com
domain.com/wp

WordPress doesn't really support this setup. All posts have saved their URL in the database, if you display the site on the secondary URL all links will still point to the primary URL.
Additionally, displaying the same content on different domains (what this is) is usually penalized by search engines, which is something you usually want to avoid.
You can achieve this by configuring the Apache with mod_proxy and mod_proxy_html to proxy all requests on one domain to the other, rewriting the URLs in the process.
The Apache config for this looks like this:
ProxyPass /wp/ http://wp.domain.com/
ProxyPassReverse /wp/ http://wp.domain.com/
# to rewrite the URLs in the HTML
ProxyHTMLEnable On
ProxyHTMLExtended On
ProxyHTMLURLMap http://wp.domain.com https://domain.com/wp
But I'd recommend to stick to a single URL and configure Apache to redirect all requests on the secondary URL to the primary.
You can do that with a single line in a .htaccess:
RewriteRule ^(.*)$ http://wp.domain.com/$1 [R=301,L]

Related

How to overwrite specific URLs to skip folder from path

I have WordPress installed in the folder /blog
I need to have a specific page that is part of that WordPress but which should not contain the segment /blog in the URL.
For example:
All my blog pages should be www.domain.com/blog/page-name
My Terms and Conditions page should be www.domain.com/terms-and-conditions
All the solutions I've found were affecting all my /blog/.. pages.
I just need a special condition for one specific page.
You need to internally pass the request to the Wordpress blog page.
This can be done through .htaccess and mod_proxy
your .htaccess file should contain
ProxyPass "/terms-and-conditions" "http://www.example.com/blog/terms-and-conditions"
ProxyPassReverse "/terms-and-conditions" "http://www.example.com/blog/terms-and-conditions"
Proxypass directive internally sent request as a proxy request.
Similar result can be expected from RewriteEngine using [P] flag like
RewriteEngine on
RewriteRule "terms-and-conditions" "http://www.example.com/blog/terms-and-conditions" [P]
Online example for the same is at .htaccess tester

Wordpress - wpml different domains - behind reverse proxy

Situation
My client has a webshop in 2 languages:
- my-website.be (Dutch + French)
- my-website.nl (Dutch)
I have to remake the /blog for these 3 languages using Wordpress.
I have no access to the main website and server, so this has to be done with reverse proxy.
Ideally this will look like this:
- my-website.be/nl-be/blog/%postname%/
- my-website.be/fr-be/blog/%postname%/
- my-website.nl/blog/%postname%/
We use WPML(pro) for translation on the website
I have to proof this is possible
The problem
I'm trying to proof this is possible with wpml + reverse proxy on my local machine using MampPro for Windows. (As I do not have real/live servers/domains available to test this) And this is not working correctly whatever I try.
The local test setup
Made 2 local servers for reverse proxy:
my-site.localbe
my-site.localnl
Made 1 local server for the blog: my-site.test
Set the .htaccess files in the 2 proxy domains to reverse proxy this:
my-site.localbe
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^nl-be/blog/(.*)$ http://my-site.test/$1 [P]
RewriteRule ^fr-be/blog/(.*)$ http://my-site.test/$1 [P]
</IfModule>
my-site.localnl
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^blog/(.*)$ http://my-site.test/$1 [P]
</IfModule>
Setup 3 languages in WPML (nl-be, fr-be, nl-nl)
Set the Wordpress site url to the default http://my-site.test
==> with this setup both reverse proxy domain just show the default homepage and/or subpages. There's no way to access the other languages.
What we've tried
Changing Wordpress wp_home and wp_siteurl to:
/nl-be/blog (as nl-be is set as the default language in wpml)
Setting up wpml as "different domain for each language", but that places /nl-be/ hardcoded after each of those different domains.
(with wp_home and wp_siteurl set as my-site.test)
Fiddling with proxypass settings in .htaccess (probably wrong)
Changing the wpml language domains hardcoded in database
Overwriting the server_name variable in functions.php as follows:
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
Combinations and variations off all above.
Results
Mostly error 500
A broken .htaccess when saving permalinks
To much internal redirections
Links looking like my-site.testbe/nl-be/blog/nl-be/*
Styling and scripts loading from wrong domain
Combinations of all above
I would like to know
if this setup is even possible (local or on real linux servers)
if the mistake is in my reverse proxy / htaccess part
if the mistake is in configuring wordpress and wpml
any information that can help me solving this.
Thanks a lot,
a developer in distress

Not able to serve different robots.txt for CDN77

We are trying to implement CDN77 in wordpress with genesis framework and want to serve different robots.txt for CDN. We used the following code
RewriteEngine On
RewriteCond %{HTTP:VIA} !^.*\.rsc.cdn77.org$
RewriteRule ^robots\.txt$ robots_cdn77.txt [L]
Our website is https://example.com and we have added a CND CNAME for https://cdn.example.com
We are facing the issue that our main robots.txt is getting rewritten alongwith the robots.txt for CDN website. Both robots.txt become same for above links. Both https://example.com/robots.txt and https://cdn.example.com/robots.txt serve the same resource.
How would I change the rewriterule such that each link serves their own robots.txt instead?
I would suggest you to setup a rule in CDN configuration. Saying for example when https://example.com/robots.txt is requested before it contacts origin server it append something like /cdn/robots.txt once the response in received from origin server, serve it as /robots.txt it self. This is possible in akamai CDN. Not sure which one are you using.

static to static url rewrite with htaccess with wordpress

I have a wordpress site with its own .htaccess automatically generated (because I'm using permalinks), than, my web-admin has configured apache to redirect any third level domain to my site, ie :
http://lol.example.com redirects to http://example.com
and than .htaccess with permalinks rules does the rest.
Now I want to write a rule in the .htaccess file that, when a user types a specific third level domain, redirects to a specific subfolder of my site, ie:
http://sprock.example.com/ redirects to http://example.com/mysprockfolder/
I know my question might sound weird, but I've never done this before so I'm quite confused.
Solved with that regex in my .htaccess:
Right before this comment (just in case you have WordPress installed):
# BEGIN WordPress
I've added the following:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?thirdlev\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/myfolder/ [R=302,L]
with a 302 redirect, everything is good!
it would be much easier for you to just go to your ftp manager and make a subdomain forward to a link. Or, you can make a redirect using php.
when redirecting make sure to add the http://www. or it will think you want to redirect to a part of your page on the site, also make sure that your subdomain has its own folder with its own files and images.

Any way to *rewrite* example.com/blog/ URL to blog.otherdomain.com?

I have a Wordpress blog hosted on one server:
http://blog.example2.com/
And another site on a separate server:
http://www.example.com
Is it possible to get the blog to be served at the following URL?:
http://www.example.com/blog/
If so, I'd love to know how. I messed around with mod-rewrite, but it looks like it will only redirect (not rewrite) to another URL, in this case.
For those interested: I realize I could install the blog on the same server, but I'd rather keep things decoupled for now.
Many Thanks
You'll need to use mod_proxy:
ProxyPass /blog http://blog.example2.com/
ProxyPassReverse /blog http://blog.example2.com/
This'll need to be in server/vhost config. Otherwise, you can use it along with mod_rewrite in an htaccess file (in your document root):
RewriteRule ^/?blog/(.*)$ http://blog.example2.com/$1 [L,P]
ProxyPassReverse /blog http://blog.example2.com/
If you're using cookies in your blog, you'll need to make sure to correct the paths/domains.

Resources