I have some really strange behavior on my subdomain.
When i enter my url in get redirected to a folder inside the subdomain.
For example:
When i enter: subdomain.domain.nl I get redirected to: subdomain.domain.nl/subdomain
I think is has something to do with this line of code inside my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
But I don't really know what to change so everything keeps redirected to https and i get rid of the redirecting inside the subdomain.
Related
I have a website in production. I have the ssl certificate working correctly. For the example.com or http://example.com or www.example.com i have a redirect to https://example.com. All good here. The problem is that when i go to www.example.com/sample1/ i get redirected to https://example.comsample1/ (see the slash missing....). It only happens with that slash because if i go to www.example.com/sample1/sample2/ i get redirected to https://example.comsample1/sample2/.
I have no idea whats going on.
here is my httacces file... not sure if its really working....
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
I included the following lines of code in my htaccess file to redirect users to the HTTPS version of my site.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www\.mysite\.com%{REQUEST_URI} [R=301,L]
</IfModule>
When I type mysite.com or www.mysite.com into the address bar it works perfect and sends me to the HTTPS version.
However if I go to Google, search for my site and click the link from the search results it still takes me to the HTTP version. I have 3 questions on this.
1) Why doesn't the browser automatically redirect once the user makes contact with the server and my htaccess file?
2) Shouldn't HTTP be turned off once HTTPS is turned on?
3) To completely make the switch do I need to use redirects or something similar from inside the Godaddy control panel?
Thanks so much!
Use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www\.mysite\.com%{REQUEST_URI} [R=301,L]
</IfModule>
With [OR] because now you redirect only http without www.
Clear your browser cache before testing.
I am trying to redirect the following (respectively):
http://sub.firstdomain.com/d/(all_files_and_folders)
http://sub.firstdomain.com/d2/(all_files_and_folders)
to
http://sub.seconddomain.com/d/(all_files_and_folders)
http://sub.seconddomain.com/d2/(all_files_and_folders)
There are other files and folders under the first subdomain that I do not want redirected. Previously this was working but now it seems like Go Daddy changed something and what I had is no longer working. Here it is:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^stats/(.+) /dstats/count.php?statspage=$1 [L,NC,QSA]
RewriteRule ^(.+)\.deb$ /dstats/count.php?file=$1.deb [L,NC,QSA]
RewriteCond %{HTTP_HOST} ^sub\.
RewriteRule ^(d2?)/(.*)$ http://sub.seconddomain.com/$1/$2 [L,R=301]
You can ignore the RewriteRule. It is working fine. I wanted to make sure I included the entire .htaccess file just in case. My issue is with RewriteCond it seems.
The following should work:
RewriteEngine On
Redirect 301 /d/ http://sub.seconddomain.com/d/
Redirect 301 /d2/ http://sub.seconddomain.com/d2/
The above should only redirect anything in the /d/ and /d2/ folder of the sub subdomain.
EDIT: Second try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1\.
RewriteRule ^(d2?)/(.*)$ http://sub2.mydomain.com/$1/$2 [L,R=301]
When I enter my website address, it does not always put www. in front of it.
This is because I type domain.com instead of adding the www. in front as this is quicker.
What code do I have to use to make sure that even if I type domain.com it always adds the www. infront.
(I believe this has to do with .htaccess mod_rewrite function?
Thank you,
Chad.
In your .htaccess file, add the following lines (replacing mywebsite.com with your real website):
<IfModule mod_rewrite.c>
RewriteEngine On
#redirects all requests to www.mywebsite.com
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com
RewriteRule (.*) http://www.mywebsite.com/$1 [R=301,L]
</IfModule>
Note that as google recommands it is better to use a 301 redirection.
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com[nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
My server is somehow configured to accept any string as a existing subdomian. This subdomains doesn't redirect, they show content instead. For example:
bla.example.com // shows the content of http://example.com
blabla.example.com // show the content of http://example.com
lorem.example.com/events/ // shows the content of http://example.com/events
So you can use "stackoverflow.example.com" and it will work.
I want to create an .htaccess rule to overwrite this behavior. I want to redirect http://*.example.com/* to http://www.example.com/*
Everything I have done so far is redirect http://example.com to http://www.example.com (wich is another behavior I want to keep)
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Thank you for your help!
Try adding the following to your htaccess file in the root folder of your domain
RewriteEngine on
RewriteBase /
#if its not www.example.com
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
#redirect it to www.example.com
RewriteRule .* http://www.example.com%{REQUEST_URI} [R=301,L]