htaccess redirect to port

1

I need to redirect subdomain.example.com -> subdomain.example.com:32400/web

My current htaccess is:

Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.example.com [NC]
RewriteRule (.*) http://subdomain.example.com:32400/web [R=301,L]

AuthUserFile /var/.htpasswd
AuthName Welcome
AuthType Basic

require user someone

IndexOptions +ShowForbidden
ErrorDocument 401 /error401.html
ErrorDocument 404 /errorGeneric.html
ErrorDocument 500 /errorGeneric.html

However I keep getting 500 Internal Server errors with the redirect enabled, if the redirect is not active then the .htaccess works fine

Rob

Posted 2014-04-01T12:43:25.370

Reputation: 121

If you get 500 errors, check the Apache HTTPD log file and see what the error was. – Der Hochstapler – 2014-04-01T12:46:45.427

Answers

0

Did you try the RewriteLog directive, with RewriteLogLevel something above 0?

Is it possible you have a rewriting deadlock; what service runs on port 32400?

Edit: The availability of RewriteLog depends on the Apache version; for Apache 2.4+, the LogLevel directive rules rewrite logging as well (see the LogLevel documentation), e.g. LogLevel rewrite:trace4

Tobias

Posted 2014-04-01T12:43:25.370

Reputation: 255

It's a plex server on 32400, im almost certain mod_rewrite is on, how could i check – Rob – 2014-04-01T13:46:03.290

Do you have access to the Apache configuration, e.g. /etc/apache2/? Nowadays, usually there is a subdirectory mods-enabled which contains symbolic links for each enabled module; in my case there is one called rewrite.load which refers to ../mods-available/rewrite.load. And/or try RewriteLog. – Tobias – 2014-04-01T16:37:06.343

0

For simple cases, you don't need to use mod_rewrite. It might be sufficient to use mod_proxy instead; something like:

ProxyPass / http://subdomain.example.com:32400/web
ProxyPassReverse / http://subdomain.example.com:32400/web 

(untested)

Tobias

Posted 2014-04-01T12:43:25.370

Reputation: 255

0

If your error documents are to be served by Apache rather than your backend server process (which serves port 32400), you need to protect them from being rewritten; e.g.:

RewriteCond !^/error(401|Generic).html

before your RewriteRule (you can chain 1 to n conditions which will all need to be met for the following one RewriteRule to be executed).

Tobias

Posted 2014-04-01T12:43:25.370

Reputation: 255