php - Would like to bypass CDN domain via HTACCESS. Need assistance for rewriting rules
Get the solution ↓↓↓I have been searching the internet for some hours and tried different solutions, but i gave up. Now trying specific here.
I am running a server for a WordPress site (Litespeed enterprise, CentOS 7) I am trying to achieve a rewrite rule in htaccess for bypassing the CDN for local visitors. e.x all static files in WP goes trough cdn.example.com (CNAME for another record at CDN provider) Now i want 1 specific country to NOT retrieve files from "https://cdn.example.com" (static files) but instead directly via origin https://example.com
I am using geoIP module for detecting users from a specific country - which works great (tested) But how can I rewrite inside WP the URLs to go trough https://example.com instead? The CDN mapping is done inside WP via Litespeed cache plugin, and it has changed all the URLs to CDN.example.com which is perfect for all non-local users, but i would like to make an exception for local users in our country, since CDN has no POP and it doesnt make a sense to route traffic to another country.
I tried this code:
RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(BE)$
RewriteCond %{HTTP_HOST} ^https://cdn.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
What am I doing wrong? Is that even correct and a valid approach?
Looking forward to hear from you :) Thanks so much
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: http failure during parsing for
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.