FlaskApp won't apply mod rewrite from htaccess

December 4, 2016 124 views
Python Apache Python Frameworks Deployment

Hi there, does anyone knows if there is anything -special- that has to be done for my FlaskApp to apply the url-rewrite pattern from htaccess? I have a fully functional FlaskApp with mod rewrite enabled, and a correct RegEx rule (tested, works) but it simply won't be applied to the URLs.

This is my htaccess:

RewriteEngine On
RewriteRule ^average_temperatures/([^/.]+)/([^/.]+)/([^/.]+)/?$ average_temperatures?city1=$1&city2=$2&city3=$3

FlaskApp.conf:


<VirtualHost *:80>
                ServerName weather-averages.co.uk
                ServerAdmin petrol.bears@gmail.com
                WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
                <Directory /var/www/FlaskApp/FlaskApp/>
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /static /var/www/FlaskApp/FlaskApp/static
                <Directory /var/www/FlaskApp/FlaskApp/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
        ServerName www.weather-averages.co.uk
        Redirect permanent / http://weather-averages.co.uk/
</VirtualHost>

and 000-default.conf

VirtualHost *:80>

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

</VirtualHost>

I enabled the log for this rule, and I see that the rule is applied, but to all other things, but the URL I want:

[perdir /var/www/] applying pattern '^average_temperatures/([^/.]+)/([^/.]+)/([^/.]+)/?$' to uri 'index.pl'

[perdir /var/www/] applying pattern '^average_temperatures/([^/.]+)/([^/.]+)/([^/.]+)/?$' to uri 'index.cgi'

[perdir /var/www/] applying pattern '^average_temperatures/([^/.]+)/([^/.]+)/([^/.]+)/?$' to uri ''

And so on...
Any help is greatly appreciated.

1 Answer

I usually overcome this with Nginx to run Port 80 to behave like a Reverse Proxy on top of my Apache Port (set to another port).

Have another answer? Share your knowledge.