I am NOOB. I am attempting to redirect specific IP addresses using htaccess to a different domain. Those ip addresses are of people copying what I type to describe stuff and put it on their site within a few hours. I want them to just see static site B while everyone else sees dynamic site A.
The code below is redirecting to cat.com which I used earlier as a test to redirect, which seemed to be working. But then I changed it to dog.com but but it is still redirecting me to cat.com. I had put a # symbol in front of the old rewriterule so it should not be in play anymore. I also checked the redirects in cpanel. This is a subdomain I am working with, not the main domain on the account. This htaccess file added only 68.14.155.149 to the redirects section nothing else.
<Files 403.shtml>
order allow,deny
allow from all
</Files>
# -- MOD: Forbid Cross Site Scripting in query
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^.*(allow_url_include|auto_prepend_file).* [NC]
RewriteRule ^(.*)$ - [F,L]
</IfModule>
# -- END MOD: Forbid Cross Site Scripting in query
deny from 180.76.5.0/24
deny from 198.23.76.220
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^38\.100\.121\.65$ [OR]
RewriteCond %{REMOTE_ADDR} ^206\.141\.173\.244$ [OR]
RewriteCond %{REMOTE_ADDR} ^68\.14\.15\0.24$
RewriteRule ^(.*)$ http://www.dog.com/$1 [L,R=301]
#RewriteRule ^(.*)$ http://www.cat.com/$1 [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^About\-us\.php$ About\-Me\.php [R=301,NE,QSA,L]
</IfModule>
#RVS END REDIRECT PAGE
Related
The following rule is allowing only www.google.com domain to access the file list.txt
My question, how can I change the rule to restrict www.google.com and allow other domain?
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(?:www\.)?google\.com$ [NC]
RewriteRule ^list\.txt$ - [NC,F]
</IfModule>
I want the browser response to 404 but not denied response.
Please test and see if this does what you want?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?google\.com$ [NC]
RewriteRule ^list\.txt$ - [NC,R=404]
but this might be clearer:
<Files "list.txt">
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?google\.com$ [NC, R=404]
</Files>
I left out <IfModule mod_rewrite.c> for clarity. If the module is not enabled, you might however prefer the server to not start opposed to just allow access.
I am having trouble with an htaccess setup. My goal is to have a wildcard sub directory point to the appropriate folder but without changing the URL. I followed some examples here on stackoverflow and elsewhere. I already have my wildcard setup in DNS, Virtual Host is good to go and mod packages. All that is left is the htaccess pointing to the matching folder without changing the url in the browser.
This Works as in I see the domain.com/example/index.html file (But the url changes from example.domain.com to domain.com/example in browser)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/%1/$1 [L,NC,QSA]
</IfModule>
When I swap out the L flag for the P flag so that the url doesnt change. When I do and I try example.domain.com the url does not change as intended but it shows me what I would see if I had went to domain.com instead of what is in the /example folder.
Here is what I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/%1/$1 [P,NC,QSA]
</IfModule>
What am I doing wrong?
You are trying to provide the URL in your substitution, which causes the redirection. Try to simply set config as follows:
In VirtualHost
ServerName example.com
ServerAlias *.example.com
DocumentRoot /path/to/your/doc/root
In htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$
RewriteCond %{REQUEST_URI} !^/%1 [NC]
# Please confirm whether you need the next line in your rules.
# I should think that it'd be required
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$
RewriteRule ^ /%1%{REQUEST_URI} [L,QSA]
I am working on a CakePHP project in shared hosting with multiple subdomains. Due to problems with Cake's htaccess I had to move the main site into a subfolder, and write a new htaccess to redirect users to this folder (while leaving the subdomains requests intact). At the minute my htaccess file looks something like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteCond %{REQUEST_URI} !^/domain/
RewriteRule (.*) /domain/$1
</IfModule>
This works for requests with 'www' prepended to the url, but there are some issues with http: // domain.com requests. In IE & Chrome this address resolves itself to the 'www' url, but in Firefox & Safari, it shows the directory structure.
I need to figure out how to include the http: // domain.com requests in the rewrite conditions without affecting the other sub-domains.
Any advice would be greatly appreciated. Thanks. Adrian
Change your %{HTTP_HOST} rewrite condition as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/domain/ [NC]
RewriteRule (.*) /domain/$1 [L]
</IfModule>
The ? in (www\.)? says zero or one occurrence i.e. makes it optional.
[L] marks it as last i.e. rewriting should stop at this rule.
[NC] makes all matches case-insensitive.
Try this for the host match:
^(www\.)?domain\.com$
I have a site, say www.test.com. Now I need to get see the site only by typing the IP address, i.e. 102.3.0.2/index.php.
For that, what I need to change in my htaccess file?
Following is my htaccess file code:
#Options +FollowSymLinks
RewriteEngine on
#RewriteBase /cash-flights/
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond $1 !(^index\.php|gif$|jpg$|jpeg$|JPG$|JPEG$|GIF$|PNG$|BMP$|png$|bmp$|js$|php$|htm$|html$|css$|ttf$|txt$|pdf$|swf$|flv$|robots\.txt$|video_chat$|.ico$)
#RewriteRule ^(?!js\/tinymce)(.*?)(\.html|\.php|\/)?$ index.php/$1 [NC,L]
RewriteRule ^(?!phpinfo\.php)(?!js\/tinymce)(?!turkeyMap)(?!cron_home)(?!quote_by_sms)(?!paypal)(?!supporttrio)(?!12all)(?!system\/application\/libraries\/libgmap)(.*?)(\.html|\.php|\/)?$ index.php/$1 [NC,L]
RewriteRule ^(.*)$ - [NC,L]
#php_value session.gc_maxlifetime 86400
<Files 403.shtml>
order allow,deny
allow from all
</Files>
deny from 100.200.200.200
Options -Indexes
Don't know if this is the reason why you are not getting it, but the ip has to be four numbers.
I.E. 102.1.10.1.
Any site name ex: www.test.com must be translated to an ip, if you can reach the site using a name you can also reach it using the ip address.
RewriteCond %{HTTP_HOST} !=123.456.789.101
RewriteRule ^(.*)$ http://123.456.789.101$1 [R,L]
But it can easily be bypassed by editing the value of the HOST HTTP header.
I've tried to set up a htaccess redirect for everyone except me. It works fine...except that I have to write an exception for every file that the under construction page wants. This will take me a while and I'm certain there is a proper way to do it, I just cant find it.
I have tried this:
order deny,allow
deny from all
allow from 205.97.194.334
ErrorDocument 403 http://www.domain.com/page.htm
<Files page.htm>
allow from all
</Files>
But I get an internal server error
What I have now is this:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1
RewriteCond %{REQUEST_URI} !/mypage\.html$
RewriteRule .* http://www.domain.com/construct/mypage.html [R=302,L]
What can I add in this to allow everything in the /construct/ ?#
Thankyou
P.S. Can anyone tell me why the first attempt didn't work?
EDIT:
Ok I've added this, which allowed the files, however, it is only redirecting when the directory is entered. I.e. domain.com will redirect to the construction page, but domain.com/index.php and anything else will not redirect
# Redirect everyone who's not from your IP
RewriteCond %{REMOTE_ADDR} !00.00.00.00 [NC]
# Allow real files to be served
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !index.html$ http://subverb.net/construct/index.html [R=307,L]
If you want /construct to be available to everyone else, and you want them to be redirected to that URL when opening any other URL:
# IF not from your address
RewriteCond %{REMOTE_ADDR} !^123\.4\.5\.6$
# AND not for /construct directory
RewriteCond %{REQUEST_URI} !^/construct
# THEN sen them to /construct/index.html
RewriteRule (.*) /construct/index.html [R=307,L]