Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to redirect www.example.com:81/site/ to www.example.com. I have used mod_rewrite a few times, is it possible to solve this in a similar way?

share|improve this question
Make sure you use a technique that returns a 301 Permanent Redirect as I might cause browsers to update their bookmarks! – Max Ried Mar 24 '14 at 8:48
But as noted in comments (below): "www.example.com:81/site/ doesn't exist anymore." – w3dk May 1 '14 at 13:48

Below is the code you can use in .htaccess file.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ http://example.com:81/$1 [P]
share|improve this answer

On example.com:81 create .htaccess file (where site/ is):

RewriteEngine on
RewriteRule  (.*)  http://example.com:80/$1  [P,L] 

With this when you go to example.com:81 the site will proxy to example.com.

share|improve this answer
I can't create .htaccess file on www.example.com:81/site/. The site doesn't exist anymore. Just www.example.com. – user37194 Mar 23 '14 at 15:03

This might do what you are looking for:

RewriteEngine on
RewriteCond %{SERVER_PORT} ^81$   # check if port 81
RewriteCond %{REQUEST_URI} ^site/ # check if it starts with "site/"
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

[R=301,L] if you want permanent redirect (the :81 taken out of SEO results for example).
Im not really sure if you have to add :80 after the %{SERVER_NAME}, please let me know so I can update the answer.

share|improve this answer

You need to have a web server running at www.example.com:81, and create a .htaccess file there.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.