I have an Angular application that pulls in content from a CMS for articles via an API. I want to utilize the XML sitemap generated by the CMS. The CMS is hosted at content.example.com and the Angular site is the www. What I would like to do is catch all .xml requests and load the content site by proxy. What I have in my .htaccess is:
RewriteCond %{REQUEST_FILENAME}
RewriteRule ^\.*?\.xml$ https://content.example.com/$2 [P,L]
However, that is not working. Fairly new to mod rewrite so I am assuming my logic is off. Not finding a lot of examples of this. Any help would be appreciated.
You could write your rule this way
# Only apply next rule when domain is www
RewriteCond %{HTTP_HOST} ^www\. [NC]
# (Proxy) rewrite all xml files to its proxy equivalent
RewriteRule ^(.+)\.xml$ https://content.example.com/$1.xml [P]
Related
I want my website to redirect from https://www.sitename.com/single-product/supplier-name/supplier-id/article-name/article-id to https://www.sitename.com/single-product and want the same original URL restored.
Currently, https://www.sitename.com/single-product/supplier-name/supplier-id/article-name/article-id URL gets me to 404
I know I will have to use the P flag in .htaccess file in document root to get this working. But I don't know why my solution is not working
RewriteCond %{REQUEST_URI} ^/single-product
RewriteRule ^(.*)$ /single-product/$1 [P]
I have found a solution not it is not working on my server. I guess mod_proxy is currently off on my server
RewriteEngine on
RewriteRule single-product/* https://www.sitename.com/single-product/ [P]
This is a great website to test these scripts
https://htaccess.madewithlove.be/
Looks like a bit easy question but I can't done that right, so I'd ask you for a little help:
I have some small site made on MODx Evo. It is placed behind CloudFlare (free tariff, very basic features used), mainly for their free https. Now I try to set only one address as a base one:
http://example.org
https://example.org <-- this one should be base
http://www.example.org
https://www.example.org
I do use default MODx Evo .htaccess to provide nice URLs and some basic PHP settings, which looks like this:
AddDefaultCharset utf-8
RewriteEngine On
RewriteBase /
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
# Exclude /assets and /manager directories and images from rewrite rules
RewriteRule ^(manager|assets|js|css|images|img)/.*$ - [L]
RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Here is everything but the part which does the redirect from www to non-www domain, and it is stock settings.
Now I need to do another two redirect conditions:
http -> https
www -> non-www
This is where I'm stuck. I can easily redirect non-www to www, but as I add http/https part, I'm getting 301 loop.
The site itself is on Apache (the Cloudflare adds their special Nginx version).
Please advice what should I add to the .htaccess shown above to have all 3 domain variants shown above redirected nicely to https://example.org one?
To my great surprise, this was possible to do with Page Rules on Cloudflare itself, which is the best solution as for me, since no backend (like my server behind the Cloudflare) involved.
Thanks Cloudflare!
.httacces may not work
I founded solution by edit config (https://gitlab.com/snippets/1906338)
To fix https thro cloudflare needs edit var $secured like this in manager/includes/config.inc.php - add checking cloudflare $_SERVER["HTTP_CF_VISITOR"]
$secured = (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ||
(isset($_SERVER["HTTP_CF_VISITOR"]) && $_SERVER["HTTP_CF_VISITOR"] == '{"scheme":"https"}');
I've got a site (example.com) and a blog (externalblog.com) which is hosted externally and reverse-proxied using ISAPI rewrite. So if you go to www.example.com/blog you're actually on externalblog.com, but the URL is masked.
I've got this working with a number of sites, but the issue is when the parent site uses HTTPS, whereas the blog is only HTTP. When visitors attempt to follow old links, the blog posts will show normally under the https version of the url, but the stylesheets are all broken and a "no certificate" warning is shown.
I need an htaccess rule that will do 2 things:
Forward anyone attempting to access an https version of a blog post only (ie anything within www.example.com/blog) to the http version instead.
Forward anyone attempting to visit example.com/blog (without the www) to http://www.example.com/blog instead of the https version, which it currently does.
However I've like the rules to only affect www.example.com/blog and nothing else on example.com. My current rule for ISAPI rewrite on example.com is as follows:
RewriteRule ^blog(.+)$ http://www.externalblog.com$1 [R=301,L]
This works correctly and is based on an article online called "using reverse proxying to pull a wordpress blog into your domain" – I can't add any more links here due to not having enough reputation.
Any help would be much appreciated.
EDIT: I tried the following
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/blog [NC]
RewriteRule ^blog(.+)$ http://www.externalblog.com$1 [R=301,L]
This works as far as rewriting https to http – but reverse proxy URL masking no longer kicks in.
Your explanation is rather unclear, so sorry if my answer will be unrelated. I suppose you are trying to force everything under www.example.com/blog to be HTTPS, instead of HTTP? Then try this rule:
RewriteEngine On
# HTTP to HTTPS redirect rule
RewriteCond %{HTTPS} off [NC]
RewriteCond %{HTTP:Host} ^www\.example\.com$ [NC]
RewriteRule ^(blog/.*)$ https://www.example.com/$1 [NC, R=301, L]
# No www. to www. redirect rule
RewriteCond %{HTTP:Host} ^example\.com$ [NC]
RewriteRule ^(blog/.*)$ https://www.example.com/$1 [NC, R=301, L]
# Your proxy rule goes here, I suppose it looks like:
RewriteRule ^blog(/.*)$ http://www.externalblog.com$1 [NC, P]
I want my site to act like this. If user inputs site.cz it should be redirected to site.eu/?lang=cs but the user should still see site.cz. Right now I have the following htaccess file:
RewriteCond %{HTTP_HOST} site\.cz [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://site.eu/?lang=cs [L,R=301]
which works great and redirects only .cz request (dont do anything with .eu requests) but it displays .eu/?lang=cs in final. Problem is that I dont only want to display site.cz all the time but also links like site.eu/folder1/file1/?lang=cs should be redirected to site.cz/folder1/file1/
Any ideas how to accomplish this?
Thanks in forward
Are you using XAMPP or a web host? Upon testing, URL rewriting isn't working in XAMPP.. Anyway, you can try to check this, just make sure that your two sites are hosted by the same web hosting account:
RewriteCond %{HTTP_HOST} site\.cz [NC]
RewriteRule ^(.*)$ http://site.eu/$1?lang=cs [P,L]
But it looks like your sites aren't hosted by the same hosting account as what you've said:
when I use [P] flag I get an error "Following URL was not found on this server" – horin
I'm setting up a new subdomain on our development server to deploy a copy of our new website.
The copy of the site is set out like this: site.develop.rav.domain.co.uk
Annoyingly all links and resources are generating their links to develop.rav.domain.co.uk
Trying to use htaccess to solve this, as has been previously managed with another subsubsubdomain. Here's what I have but it isnt working
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^develop\.rav\.domain\.co.uk$ [NC]
RewriteRule ^(.*)$ http://site.develop.rav.domain.co.uk/$1 [L,R=301]
Not done much with htaccess before so any help will be appreciated
On closer inspection the URL being written for resources is: ukcl-rav-vdev01\.rav\.contactlaw\.co.uk