I have like 10 addon domains on my main website, and atm you can visit any addon (call it test1.com) website with link as test1.mainwebsite.com or www.mainwebsite.com/test1
How can I block this access to addons?
I have tried this, but this block only www.mainwebsite.com/test1 way.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mainwebsite.com$ [NC]
RewriteCond %{REQUEST_URI} ^/google.com/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/something.net/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
Disable access to a subdomain
The following is an example '.htaccess' code which provides a thorough means of making the Addon domain folders, and their contents, invisible through the main domain by forcing a "404 Not Found" error. This will work both for web browsers and search engines:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addonfolder/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
Related
My application webroot is like : /home/username/appname/public_html
I have created a subfolder under public_html and installed the wordpress there.
Like: /home/username/appname/public_html/subfolder
we used the below redirection code because we want to access the application like https://example.com/subfolder
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://example.com/br/$1 [L,R=301,NC]
RewriteRule ^/?(.*)$ http://example.com/br/$1 [L,R=301]
so when user will access main domain example.com so req will be redirected to example.com/subfolder/
but now we want to access example.com/file.txt
but the problem is due to redirection it also redirecting
so how can I exclude this url example.com/file.txt from redirection to example.com/subfolder/file.txt
Please help us.
I tried to add these config but did not work for me
RewriteCond %{REQUEST_URI} !^/file\.txt$
OR
RewriteCond %{REQUEST_URI} !^example\.com\/file\.txt$
I am in a situation where an user can create his blog in a subdomain.
Users will create blogs and enter the address he wants like say,
abcd.domain.com Then my php code creates a directory called abcd.
To view the blog user will type in abcd.domain.com in his browser and I want a .htaccess code which will rewrite the url and open the files inside the domain.com/abcd
But for the user the url in the browser should stay abcd.domain.com
Currently I am trying this code
RewriteCond %{HTTP_HOST} ^test\.domain\.com$
RewriteCond %{REQUEST_URI} !^test/
RewriteRule ^(.*)$ /test/$1 [L,QSA]
But this gives me 404 even though I have a file test.html inside the test folder and trying to view that page.
Also in this situation I will have to manually make change to the .htaccess file for URL rewrite. What I want to know is if it is possible to have a wild card subdomain redirect to the respective directory.
You can use:
RewriteCond %{HTTP_HOST} ^test\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/test/
RewriteRule ^(.*)$ /test/$1 [L,QSA]
REQUEST_URI with leading /.
With wild card subdomain:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/%1/
RewriteRule ^(.*)$ /%1/$1 [L,QSA]
Note that it takes more than a rewrite rule to have wildcard subdomains. Just fyi.
You need to have created a wildcard DNS record for subdomains and also tell apache to use any subdomain request by having a ServerAlias of *.domain.com in the apache config.
Then try your rule this way and see if it works for you.
RewriteCond %{HTTP_HOST} ^((?!www).+)\.domain\.com$ [NC]
RewriteCond %1::%{REQUEST_URI} !^(.*?)::/\1/?
RewriteRule ^(.*)$ /%1/$1 [L,QSA]
I've found a few threads with similar issues, but haven't had any luck modifying the answers to try and meet the requirements of my site. I have a primary domain, and re-write rules in place to redirect www domain to non-www domain, mapped like this:
primarydoamin.uk => primarydomain.uk
www.primarydomain.uk => primarydomain.uk
RewriteCond %{HTTP_HOST} ^primarydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.primarydomain.uk$
RewriteRule ^(.*)$ primarydomain.uk/$1 [R=301,L]
I've a number of add-on / mapped domains against my hosting and I'd like to rewrite based upon a pattern:
drop 'www'
rewrite to a sub-directory of the primary domain (with periods '.' replaced to dashes '-')
only execute when the above rule, redirecting www domain to non-www domain traffic is not met, for example:
www.fishandchips.co.uk => primarydomain.uk/closed/fishandchips-co-uk
www.mushypeas.com => primarydomain.uk/closed/mushypeas-com
pukkapie.uk => primarydomain.uk/closed/pukkapie-uk
Currently I'm copying and pasting the following logic:
RewriteCond %{HTTP_HOST} ^(www.)?fishandchips.co.uk$
RewriteRule ^(.*)$ http://primarydomain.uk/closed/fishandchips-co-uk [R=301,L]
Your first set of rules can be resumed as:
RewriteCond %{HTTP_HOST} ^(www\.)?primarydomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.primarydomain.uk$ [NC]
RewriteRule ^ http://primarydomain.uk%{REQUEST_URI} [R=301,L]
For your second set of rules I would try something like:
# This one will work for domains with single extension like .com
RewriteCond %{HTTP_HOST} ^www\.([^\.]+)\.([^\.]+)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.([^\.]+)$ [NC]
RewriteCond %{HTTP_HOST} !primarydomain.uk$ [NC]
RewriteRule ^ http://primarydomain.uk/closed/%1-%2%{REQUEST_URI} [R=302,L]
# This one will work for domains with 2 extensions like .co.uk
RewriteCond %{HTTP_HOST} ^www\.([^\.]+)\.([^\.]+)\.([^\.]+)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.([^\.]+)\.([^\.]+)$ [NC]
RewriteCond %{HTTP_HOST} !primarydomain.uk$ [NC]
RewriteRule ^ http://primarydomain.uk/closed/%1-%2-%3%{REQUEST_URI} [R=302,L]
The %{REQUEST_URI} at the end will ensure it passes down any URL it was coming from that domain.
NOTE: Keep in mind this is an untested solution. It should work as expected, however it does not take into account multilevel sub domains into it, which you will have to adjust as you go.
Also I have set it to 302 instead of 301, use 302 until you confirm its fully working then move it to 301 and also make sure you're using a different browser or cleared your cache to make sure you're not viewing a cached redirect.
Well it's kind of hard typing a title to describe what I want to do.
Basically I have a website that I've been asked to develop a mobile site for. This website has various domains (such as .co.za,.com,.za.net) but they all run from the same folder on the server (so I only have one .htaccess file).
I want to be able to redirect the traffic that goes to www.example.co.za to m.example.co.za and traffic that goes to www.example.com to m.example.com.
How would I need to modify this .htaccess file to achieve that.
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte" [NC]
RewriteRule ^$ http://m.example.com/ [L,R=302]
How about:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte" [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ http://m.%2/ [L,R=302]
I have been having a very difficult time editing my .htaccess file to do these three things together. I have been able to get each part separately but I just do not understand how the logic flow works to get them all to work.
This is the best I have been able to pull together using the demo at bluehost support
http://helpdesk.bluehost.com/index.php/kb/article/000347
I appreciate any help resolving this issue.
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
# Bluehost.com
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?sampleurl.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/folder/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /folder/$1
# Change yourdomain.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your folder, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?sampleurl.com$
RewriteRule ^(/)?$ folder/index.php
RewriteCond %{HTTP_HOST} ^sampleurl\.com$ [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://www.sampleurl.com/$1 [L]
# For security reasons, Option all cannot be overridden.
# Options All -Indexes
# Options ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch -Indexes
Update:
Well after a long time using the following I have run into issues.
IndexIgnore *
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule (.*) https://www.example.com/site/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/site/
RewriteRule (.*) https://www.example.com/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule (.*) https://www.example.com/site/$1 [L,R]
New Issues.
Bluehost has an application that quickly installs and updates open source applications like wordpress, joomla, phpbb etc. Well apparently my new super .htaccess file completely breaks their system. The only way I can run updates and installs is to move the .htaccess to .htaccess.bak until the upgrade or install is complete. Then move it back.
I can't create any .htaccess on other sites that I host in other directories. e.g. I have a master account that I store in /www/site/ that this script forces requests into. Unfortunately my other sites stored in /www/site2/ and /www/site3/ don't work well. First I have to create a blank .htaccess to prevent it from pulling the .htaccess above found in /www/. For some reason if I try to do anything like force www.site2.com I get 500 error's saying I am forcing too many redirects.
I have a theory that my solution above needs to be a little more specific, to make sure it only effects request sent to example.com. (I think the line with anything not containing /site/ is a little to broad).
I appreciate any support resolving this. Would save me a bit of headaches!
Update II:
I do not believe I have access to apache config. Only option I see in cpanel is apache handlers (not really sure what that section does).
I will submit a ticket to see what location the simplescripts server runs from. I believe it runs from "https://www.simplescripts.com". What edit would you recommend I add to ignore this domain?
My host bluehost starts you with a primary account and then subdomains. The primary account's location is set at user\www. Unfortunatly this gets messy when you try to host multiple domains. That is why I use .htaccess to force requests that hit that directory into the \site\ directory. Thus trapping the primary site into the \site\ directory.
I think the relocation issue I was having with one of my subdomains was due to wordpress trying to force a domain without www and then me writing an .htaccess file forcing www. That caused the infinite loop, not my .htaccess file this thread is about. If I can resolve the simplescripts issue I am gmoney ;)
I'd think something like this would work
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) https://www.example.com/folder/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/folder/
RewriteRule (.*) https://www.example.com/$1 [L,R]
but I confess I haven't tested. You can add in all the don't redirect if the file exists, etc., if you want.
In case you haven't seen it, here is the mod_rewrite documentation.
edit:
In response to updated question:
The first thing I notice is that it appears you may have enough control over your setup to put the rewrites in the Apache config files (in the VirtualHost sections) instead of in htaccess files, that'll immediately solve your problem with your other sites.
The first problem, it sounds like you'll need to add RewriteCond to exclude whichever URLs the Bluehost software uses. Either that, or access the Bluehost software under a different VirtualHost (once you've put the rewrite stuff inside the VirtualHost blocks).
If you can't edit your Apache config, then the easiest fix for the other sites it to not make them a subdirectory (on the filesystem) of your main site. That's rather weird, anyway. Move your main site to a sub-directory of /www as well if need be.
Personally, I put all sites in /srv/www/com.site-name.www on my servers (that is, reverse order, with the top-level-domain first, it makes related stuff group together when sorted alphabetically. E.g., when you have www.example.com and static.example.com)
This seems to do everything I needed. Probably a shorter way to get this done but it works!
IndexIgnore *
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) https://www.example.com/folder/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/folder/
RewriteRule (.*) https://www.example.com/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) https://www.example.com/folder/$1 [L,R]