Stop subdomain redirecting to main domain - html

When I search for the subdomain.domain.es I'm redirected to domain.es.
Code in htaccess file:
RewriteEngine On
RewriteBase / RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://dominio.es/$1 [R=301,L]
My hosting company gave me the htaccess so my web was redirected from http to https but I have no clue of what any of this code means.
I'm new to web programming so I hope you can help.
Thanks so much!

This answer worked for me. I hope this can help someone else!
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Related

Redirect from one website to another and keep directory

The blog section of a website moved from a subdomain to a directory of the main domain. I need to redirect all users visiting blog.site.com to site.com/blog/ and the directory someone enters should be kept when forwarding, e.g. blog.site.com/post/welcome should point to site.com/blog/post/welcome
I treid adding this to my .htaccess file which I placed in the subdomain's directory via FTP:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.herderzeitung.de$ [OR]
RewriteCond %{HTTP_HOST} ^www.blog.herderzeitung.de$
RewriteRule (.*)$ https://herderzeitung.de/blog/$1 [R=301,L]
However, this doesn't seem to be working. I was also wondering, what the most SEO friendly way is to achieve this (the site permanently moved to another domain).
Thanks in advance!
Try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.herderzeitung\.de$ [OR]
RewriteCond %{HTTP_HOST} ^www\.blog\.herderzeitung\.de$
RewriteRule ^/?(.*)$ https://herderzeitung.de/blog/$1 [R=302,L]
I've escaped the dots, and anchored&normalized the pattern. Also switched it to temporary redirects (302); once you know it works, then change it to 301 again for SEO reasons.
And yes, as far as i know 301s are the best method for retaining your search rankings and the like.
This seems to work:
RewriteEngine On
RewriteCond %{REQUEST_URI} (.*)
RewriteRule ^(.*)$ https://herderzeitung.de/blog/$1 [L,R=301]
Thank you everyone!

.htaccess http to https not working

despite searching for previous answers, I couldn't see one which addresses my issue, so hope someone can help?
I recently redirected an old html company site to a new wordpress site with .htaccess rules (obvs different domain)
however, shortly afterwards I updated the new domain with an ssl cert. The old site was just a regular http:
I changed the .htaccess rules for the https: but obvs I have done it incorrectly as the redirect does not work.
this is what I am using.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain.co.uk$ [OR]
RewriteCond %{HTTP_HOST} =www.old-domain.co.uk
RewriteRule (.*) https://newdomain.com$1 [R=302,L]
</IfModule>
what do I need to change to have it redirect correctly?
thanks for your assistance.
I prefer this variant for redirecting from http to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Also there are a lot of plugins for wordpress that help with that. They also help with redirecting all request to resources (images etc) to https
It works for me.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]

htaccess why is site redirecting to //

In my htaccess I am redirecting all non https to https.
It works, but its also adding in an extra '/', so the url is
'https: //www.[MY SITE URL].co.uk//'
Why is this? To be honest, I don't really know what all this in my htaccess is doing, its copied from googling answers to 'redirect all requests to https'
My htaccess:
Options -MultiViews
RewriteEngine On # Turn on the rewriting engine
RewriteBase /
#RewriteCond %{HTTP_HOST} ^(www\.)?jobooz\.com [NC]
#RewriteRule ^(.*)$ https://www.jobooz.co.uk/$1 [R=301,L,NC]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/$1
RewriteRule ^/?$ /php/index.php [NC,L] # Home page
I've also noticed any deeper urls like '/search-jobs/jobs-near-me' that I add to the url then get duplicated too, to '/search-jobs/jobs-near-me/search-jobs/jobs-near-me' when redirected to https.
All urls work fine if I go directly to the https version.
Any help appreciated, thanks.
The following rewrite rule has a problem:
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
The gist of why you are seeing repeated fragments in the rewritten URL is that (.*) matches everything, and that already includes the host and URI. Instead, you can try redirecting any incoming request on port 80 to HTTPS.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Need Help in my website IP Canonicalization .htaccess

i have searched the whole internet to find solution my website is www.hrxlevels.tk and ip address associated with website is this 31.170.163.33 and want the .htaccess for ip to redirect to domain
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteEngine On
RewriteCond %{HTTP_HOST} ^hrxlevels.tk [NC]
RewriteRule ^(.*)$ http://www.hrxlevels.tk/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^31\.170\.163\.33
RewriteRule ^(.*)$ http://www.hrxlevels.tk/$1 [L,R=301
RewriteBase /
and this code is not working for ip canonicalization but works great for url cononicalization please help please!
please use this detail and please write the .htaccess file for my website.
My webhost is 000webhost.com

.htaccess redirect

Just wondering if someone can help me with the following issue.
I want to redirect my site to a subdomain, whishc simply displays a maintenace page, allowing me to work on the main site.
So I have the following code for my .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.co.uk$
RewriteRule ^/?$ "http\:\/\/maintenance\.domain\.co\.uk" [R=301,L]
However, I need to access the root domain to be able to view the work that I have done; however, I only want myself on my IP to be able to view that and the outside world is redirected to the subdomain which displays the maintenace page.
I would have thought that the following code:
RewriteCond %{REMOTE_HOST} !^00\.000\.00\.000
Would have allowed me to do that; however, I'm still being redirected to the sub domain and I wondered is someone could assist me further wth this.
Thanks
You'd be better of using %{REMOTE_ADDR}, I believe:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [NC]
RewriteCond %{REMOTE_ADDR} !=00.00.00.00
RewriteRule ^/?$ http://maintenance.domain.co.uk/ [R=301,L]