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
etc...
Do you have a suggestion on how to do this via .htaccess mod_rewrite?
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With