I have created a subdomain and want to redirect it to a URL. But I want to keep the subdomain as the URL of the redirection. I have searched for it but none of them worked for me!

  Subdomain:   sub.domain.com    
  New URL:

.htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sub\.domain\.com$
RewriteRule ^/?$ "http\:\/\/10\.10\.10\.10\:8080" [R=301,L]

1 Answer 1


You have a few fundamental problems with your last line.

RewriteRule ^/?$ "http\:\/\/10\.10\.10\.10\:8080" [R=301,L]

Change it to:

RewriteRule .* [R=301,L]

Of course, I assume that the IP address in your example is just an example and that you are not trying to redirect to a private IP address that is not routable. As well, port 8080 is not an HTTP protocol and that you do have a web server answering that port.

  • Redirect works fine but the URL is changing to new URL: I want to keep the subdomain RUL.
    – Hamed
    Jul 24, 2016 at 4:26
  • @hamed Try a 302 and see what happens. If that does not work, then try removing the [R=301,L] entirely and see if that does what you want.
    – closetnoc
    Jul 24, 2016 at 5:06
  • @hamed If is another server, you may not have too many options. Redirect or Proxy, which I do not recommend - it is a security nightmare if you do not know what you are doing, may be all you can do.
    – closetnoc
    Jul 24, 2016 at 5:29
  • It is the same. The URL is the
    – Hamed
    Jul 24, 2016 at 5:36
  • 1
    Yes, is another server which is not assigned to any domain. I think I should use proxy. I have tried proxy which worked fine but I couldn't redirect to port 8080.
    – Hamed
    Jul 24, 2016 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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