I’m trying to redirect my user to a certain website when they visit one of my end point.
https://url-shortner-in.azurewebsites.net/openfb will point to google.com
My server is hosted on Azure App Service with Slim Framework v4 using REST API.
This is my call to redirect the user.
return $response
->withHeader('Location', 'http://www.google.com')
->withStatus(302);
It’s working fine on my local WAMP server. I’m getting redirected to Google.
But after uploading it on Azure App Service, the code isn’t working.
I’m seeing a blank page after redirection. The URL stays the same (my website URL and not Google’s.)
Is there any misconfiguration with Azure?
My .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
2
Answers
I suggest you choose windows platform when create webapps.
You can try to create
web.config
file under the wwwroot folder, if it doesn’t exist. If you can find this file when deployed your webapp, you need to modify it.The specific content to be added or modified is that
RewriterConfig
needs to be added to web.config.The format is as follows:
For more details, you can refer to the following two posts:
Azure Web App Angular Not redirecting to www
DNN UrlRewrite (“DotNetNuke.HttpModules.UrlRewriteModule, DotNetNuke.HttpModules”) does not run custom rewrite rule on web.config
Step 1: Enable Apache .htaccess
By default, the .htaccess file is not enabled.
1. Open the default host configuration file by entering the following command in the terminal:
2. Locate the section labeled
<Directory /var/www>
.In that section, change the
AllowOverride None
entry toall
:Save the file and exit.
3. Next, restart the Apache service: