How to redirect and keep the previous URL with .htaccess?

How to redirect and keep the previous URL with .htaccess? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the How to redirect and keep the previous URL with .htaccess? error on your web browser. Problem :


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: 10.10.10.10:8080


.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]

Solution :

You have a few fundamental problems with your last line.



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


Change it to:



RewriteRule .* http://10.10.10.10:8080 [R=301,L]


Of course, I assume that the IP address 10.10.10.10 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.


We hope that this article has helped you resolve the domains, htaccess, redirects error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments