skip to Main Content

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


  1. 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:

    <configSections>
     <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter" />
    </configSections>
    ......
    <RewriterConfig>
       <Rules>
          <RewriterRule>
            <LookFor>^default/([0-9]+)/([_0-9a-z-]+)</LookFor>
            <SendTo>11.aspx?id={R:1}</SendTo>
          </RewriterRule>
       </Rules>
    </RewriterConfig>
    

    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

    Login or Signup to reply.
  2. 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:

    sudo nano /etc/apache2/sites-available/default
    

    2. Locate the section labeled <Directory /var/www>.
    In that section, change the AllowOverride None entry to all:

    AllowOverride All
    

    Save the file and exit.

    3. Next, restart the Apache service:

    sudo systemctl apache2 restart
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search