Prevent AddOn domain from redirecting to subdomain (Bluehost) - subdomain

Hi my AddOn domain keeps on redirecting to a subdomain.
I also noticed that this also happens when I try accessing the folder where I pointed the AddOn domain
AddOn Domain: addon.com
Subdomain: addon.maindomain.com
Subfolder: maindomain.com/addon
Why is this so? I've seen from the Domain Manager a message like this though.
Addon Parent: The domain addon.com is aliased to addon.maindomain.com
How can I prevent the redirection from happening?

Try either of these:
file: maindomain/.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
or
file: maindomain/addon/.htaccess
writeEngine On
RewriteCond %{HTTP_HOST} ^addon.maindomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.addon.maindomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^addon.com$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.addon.com/ [R=301,L]
Cheers!
Ref:
https://my.bluehost.com/cgi/help/498
https://my.bluehost.com/cgi/help/134

Related

How To make Custom Links Without Showing page not found error [duplicate]

I want to redirect all pages on my site (including index) to UnderWork.html
and I'm doing this using .htaccess with this code:
RewriteEngine on
RewriteRule ^(.*)$ UnderWork.html
...and its works fine.
Now I am adding some more code to my .htaccess to redirect all traffic to the non-www domain and now my code looks like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.in
RewriteRule ^(.*)$ http://domain.in$1 [R=permanent,L]
RewriteRule ^(.*)$ UnderWork.html
Here is where I have a problem. If I enter a URL like: domain.in/xyz then it works as before, but if I use a URL like: www.domain.in/xyz then Apache converts it to coincart.inxyz/.
What am I doing wrong here? How can I get what i want? Thanks in advance.
Below are rules that work for me:
RewriteEngine On
# Adding trailing slash for directory requests.
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/www$
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.+[^/])$ http://example.com/$1/ [R=permanent]
# External redirection from www subdomain to non-www domain.
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^/?(.*) http://example.com/$1 [L,R=permanent]
# Internal redirection to index.php for nonexistent URLs.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|png|gif)$
RewriteRule . /index.php [L,QSA]
To show a custom page when a directory root (domain root in particular) is requested, use the Apache's DirectoryIndex directive:
DirectoryIndex UnderWork.html

Attempting to remove "www" and force "https" on domain and trying to make it do both

RewriteEngine On
#Remove www
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
#force https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#ignore folder for removing slash & removing .html
RewriteRule ^(whmcs) - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
So this is my current code. Here is my results:
website.com --> https://website.com
http://website.com --> https://website.com
www.website.com --> https://website.com
http://www.website.com --> https://website.com
All good except...
https://www.website.com --> https://www.website.com <--No good.
I have been researching and attempting to rewrite this to no success. Please any help and if you would be so kind to leave documentation so I could read further. Either way I need a solution. Thank you!
You have written so many re-writing conditions to remove www and force https. If they not any other specific needs then you can just try this simple solution
RewriteRule (.*) https://website.com/$1 [R=301,L]
I had the same issue before, here is how i fixed it.
### WWW & HTTPS
#Remove WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
### WWW & HTTPS

Htaccess file redirects wrong ip's

I'm trying to redirect spam ip's from my website to a different website.
For some reason the following code in my .htaccess file redirects me (my ip) to the www.underconstruction.com despite my ip not being included. My ip has the following format 5.64...
Please, could you help me improve the following code so that it redirects only the listed ip's / ip ranges to www.underconstruction.com
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^88\.208\.201\.208 [OR]
RewriteCond %{REMOTE_ADDR} ^209\.190 [OR]
RewriteCond %{REMOTE_ADDR} ^209\.51 [OR]
RewriteCond %{REMOTE_ADDR} ^5\.101 [OR]
RewriteCond %{REMOTE_ADDR} ^62\.210 [OR]
RewriteCond %{REMOTE_ADDR} ^62\.212
RewriteRule ^/* http://www.underconstruction.com/ [L]
Have you checked your error log? Try to use REMOTE_HOST instead of REMOTE_ADDR
The problem can be solved by using the following code in the .htaccess file. The REMOTE_HOST parameter has been used instead of the REMOTE_ADDR
RewriteEngine On
RewriteCond %{REMOTE_HOST} ^88\.208\.201\.208 [OR]
RewriteCond %{REMOTE_HOST} ^209\.190 [OR]
RewriteCond %{REMOTE_HOST} ^209\.51 [OR]
RewriteCond %{REMOTE_HOST} ^5\.101 [OR]
RewriteCond %{REMOTE_HOST} ^62\.210 [OR]
RewriteCond %{REMOTE_HOST} ^62\.212
RewriteRule ^/* http://www.underconstruction.com/ [L]

Permanent redirect after removing html extension in htaccess

I have these htaccess rules to remove html extension from urls:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
It works fine but I can still access from the URL with extension. How to make it so that when a user click the url with extension, will be redirected with a permanent (301) redirect to the extensionless url?
Thanks
Just add the little snippet at the end which indicates it is a 301 redirect.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [R=301,L]

Exclude certain subfolders and domains in redirects

This is a continuation from Redirect only HTML files?
How can I change my .htaccess to make it exclude certain subfolders or subdomains from the HTML-only redirect? I tried doing using this code to exclude the 'downloads' subfolder and the 'dev' and 'support' subdomains, but it didn't work:
RewriteCond %{HTTP_HOST} ^pandamonia.us$ [OR]
RewriteCond %{HTTP_HOST} ^www.pandamonia.us$ [OR]
RewriteCond %{HTTP_HOST} !download [OR]
RewriteCond %{HTTP_HOST} !faq
RewriteCond %{HTTP_HOST} !support [OR]
RewriteRule /.+\.html$ "http\:\/\/pandamonia\.us\/" [L]
You need to check REQUEST_URI or the whole match of the RewriteRule $0 for this; HTTP_HOST does only contain the host name of the current request. You also need to change the logical expression of your condition:
RewriteCond %{HTTP_HOST} ^pandamonia\.us$ [OR]
RewriteCond %{HTTP_HOST} ^www.pandamonia\.us$
RewriteCond %{REQUEST_URI} !^/download/
RewriteCond %{REQUEST_URI} !^/faq/
RewriteCond %{REQUEST_URI} !^/support/
RewriteRule /.+\.html$ http://pandamonia.us/ [L]
For those looking for a quick bit of insight into Gumbo's previous reply (where he mentions the situations for when to (and not to) use [OR], I found this WMW thread very helpful: http://www.webmasterworld.com/apache/3522649.htm