Answer the question
In order to leave comments, you need to log in
How to implement htaccess proxy for link with working iframe and ajax requests?
Now the situation is as follows: there is an example.com domain and product pages, each available at its own address:
- example.com/product-one
- example.com/product-two
- etc
All these pages are processed by one Yii action (htaccess has a RewriteRule, which leads to index.php?r=sale/product&product_id=%SOME_ID%). Each product has a link with an html file uploaded to the server, which has relative paths and therefore this html file is loaded on the product page in the IFRAME. So resources are not lost with relative paths. I process events in this html through jQuery scripts written on the product page, there is validation and ajax requests.
Now the task arose to register a separate domain for each product. For example:
-product-one.com => example.com/product-one (or example.com/index.php?r=sale/product&id=1 )
- product-two.com => example.com/product-two (or example .com/index.php?r=sale/product&id=2 )
- etc
I write the rule like this:
RewriteCond %{HTTP_HOST} ^product-one.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) http://example.com/product-one [P]
XMLHttpRequest cannot load http://example.com/index.php?r=debug%2Fdefault%2Ftoolbar&tag=57cc3a8c22a51. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://detox-plus-monster.local' is therefore not allowed access.
Answer the question
In order to leave comments, you need to log in
Okay, so far I've only found how to change the baseUrl from the controller so that it doesn't throw AJAX errors due to security issues.
1. I pass the baseUrl = product-one.com GET parameter to htaccess 2.
I write in the controller:
public function actionProduct($id, $baseUrl = null)
if (!empty($baseUrl)
Yii::$app->set('urlManagerFrontend', [
'class' => 'yii\web\UrlManager',
'baseUrl' => $baseUrl,
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
]);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question