.htaccess mod_rewrite IP-based redirect: how to redirect all traffic to a specific subdirectory, except my IP?

htaccess redirect page
htaccess redirect to ip
htaccess rewrite
htaccess redirect based on country ip
redirect all ip except htaccess
htaccess example
htaccess redirect ip range

I want my visitors to have access only to a specific part of my website (blog). If they try to access other areas of the website, I'd like them redirected to the blog section.

I also want this to apply to everyone except to my IP address.

So the structure is as follows:

mysite.com/blog // visitor access allowed

mysite.com        // redirect to mysite.com/blog

mysite.com/forum  // redirect to mysite.com/blog

mysite.com/tools  // redirect to mysite.com/blog


Do you have a suggestion on how to do this via .htaccess mod_rewrite?

You should be able to redirect with the following:

RewriteCond %{REMOTE_HOST} !^123\.456\.789
RewriteCond %{REQUEST_URI} !^/blog/?
RewriteCond %{REQUEST_URI} /(.*)$
RewriteRule (.*) /blog [R=301,L]

How to Redirect an IP Address Using a Hosts File, You can create/edit the .htaccess file using File Manager in cPanel, but make sure to replace the numbers with your actual IP address. You can find what  Redirecting a URL. Using Redirect in an .htaccess file enables you to redirect users from an old page to a new page without having to keep the old page. For example, if you use index.html as your index file and then later rename index.html to home.html, you could set up a redirect to send users from index.html to home.html.

You should create a page that handles the specific redirects, and then edit your htaccess file to be something like this:

Options +FollowSymlinks
RewriteEngine on
#not your IP
RewriteCond %{REMOTE_HOST} !^123\.123\.123\.123
#make sure the rule allows everyone to access the redirect page
RewriteCond %{REQUEST_URI} !/redirect_page\.html$
#Send them to the redirect page
RewriteRule \.html$ /redirect_page.html [R=302,L]

The rediret_page.html can have either js or server-side redirection that handles where they end up, but it will force everyone who has not come on your IP address through a specific page that handles redirection.

How to redirect all visitors except your IP to another website?, Note that many of these examples won't work unchanged in your particular server You can use mod_rewrite to redirect these URLs to the new server, but you or in a .htaccess file), so that the -f checks are looking at the correct directory path​. If we can't do a lookup on their IP address, we fall back to a default server. I have 8 lines of rewrite rules in my .htaccess file. I need to exclude two physical directories on my server from these rules, so they can become accessible. For now all requests are sent to index

Just add your IP Address in..

order deny,allow
deny from all
allow from xxx.xx.xxx

Redirecting and Remapping with mod_rewrite, Creating an .htaccess file on your DreamHost web server Redirect "ALL" requests to a domain to a subdirectory Rewrite all those to insert /folder RewriteRule ^(. How can I redirect and rewrite my URLs with an .htaccess file? .htaccess overview · Force your site to load securely with an .htaccess file  How to Redirect specific page on specific domain alias to https/SSL. The webhosting is setup with multiple domain aliases on the same vhost. It needs to redirect a specific page on a specific domain alias to https.

Redirect your root directory to a subdirectory – DreamHost , Part 1 - How do I redirect all links for www.example.com to example.com ? specifies that the next rule only fires when the http host (that means the domain of the queried url) is not (- specified with the "! Redirect visitors to a new site Copying the content of the old website to the new website is the first step - but what  Redirect Old Domain to New Domain via .htaccess When you migrate a site from one domain to another, it is very important that you don’t break all the links that you built to your old domain. Proper redirection of all the pages on the old domain to the same location on the new domain will ensure that visitors to the old domain will end up in the right place.

How To Redirect Rewrite Using The htaccess File, With clean URL's enabled, when running other software applications in The trick is to modify .htaccess to ignore specific files/folders. To redirect all users to access the site WITH the 'www. Drupal to have visitors look into my /all dir and subdirs, seeing all files contents but not executing them; why not? 2. Edit the contents of the htaccess.txt file. Below are some example redirects you can use. They are labeled in accordance to what actions they will perform. 301 (Permanent) Redirect: Use a 301 redirect .htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations.

Configuring .htaccess to ignore specific subfolders, Important note about redirecting via mod_rewrite; Redirect from “www” domain to Finally, .htaccess rules apply to the parent directory and all subdirectories. In the following example, all IP addresses are allowed access except for This is how to block unwanted visitors based on the referring domain. With a CMS like WordPress or Drupal, you can do most things you want to do with a .htaccess file. Such as block IP addresses or redirect URLs — from right inside the application. Often, CMS works hand-in-hand with the .htaccess file, adding directives programmatically.

  • thanks @jordon - if I want to add more than one IP address, what would the syntax be?
  • @torr Just copy the first line to another line and keep adding them.
  • I think REMOTE_ADDR is preferable to REMOTE_HOST in order to get the IP address. REMOTE_HOST will not necessarily return the IP address if HostnameLookups is enabled (although this is Off by default).
  • to clarify, I do not want my users to a redirect page - I want them to go to the front page of my blog (wordpress) which typically shows if I manually point the browser to mysite.com/blog -- does your code provide for this?
  • @torr: All you need to do is make the redirect page /blog then. I might recommend going through a PHP redirect page anyway, as it will give you better control, but it should work just using /blog