htaccess rewrite rule overpowers deny ip - wordpress

I'm trying to deny access to my WordPress site while it's under construction. I have denied all other IP which appears to work fine when I comment out WP part of htaccess. When WP part of htacess is present and I access from forbiden IP, index.php page gets displayed, just without css or images.
Can someone explain how it happens and how to prevent it?
Thanks!
# ALLOW USER BY IP
<Limit GET POST>
Require all denied
Require ip 93.112.174.
</Limit>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

One answer from user got deleted so I can't mark it as solution... Thanks! :)
Using rewrite rules was most simple way to achieve what I wanted, works fine on latest stable Apache 2.4.18
<If "-R '93.112.0.0/16'">
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
</If>
<Else>
RewriteEngine On
RewriteRule ^ - [F]
</Else>

Related

.htaccess rules for subdomain to force https on all pages

I have several sites as sub-domains with a main domain called site1.com. My main domain has a wildcard ssl certificate for *.site1.com. My subdomains can be referenced as site2.site1.com, site3.site1.com to siteN.site1.com. My main domain uses the certificate correctly and forces https on all pages, my subdomains only use https on the admin pages, I'm using a wordpress CMS or I can force the certificate to be used if I reference my sites as https://site2.site1.com, https://site3.site1.com etc. I want to get my subdomains running as https://site2.com. Currently my domain works as http://site2.com or http://site1.site2.com
PS: I have no access to the vhost file. Here is my .htaccess code for all my domains:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
</IfModule>
I found a simple plugin that did the job for me. This is what my .htaccess file looks like now for my sub-domain:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
#RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
</IfModule>

redirect my site from example.info to www.example.info using .htaccess

i have just completed making a site using wordpress. i can access my site using the site's url which is for example 'example.com'. now what i want is whenever someone enter example.com in their browser's address bar i want it to appear http://www.example.com. also on on any other post and pages as: http://www.example.com/page, http://www.example.com/post .i know this is done by writing some redirect thing on .htaccess file,but i just dont know what.currently by deafult my .haccess file contains this code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You can do it in 2 ways:
Use WP settings
Use .htaccess
For 2. modify your rules to this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Why is so complicated? It's So simple.
Login to Wordpres
Go To Settings >> General
Change WordPress Address (URL) & Site Address (URL) - add www in your URL
Save Changes....
It's Done

redirect WP post from one subdomain to WP page on domain subdirectory using htaccess- file

I got a issue with my htaccess-file. I learned a thing or two when it comes on rewriting through the htaccess-file, but this one is really keeping me awake. Hopefully one of you can help me solve with this matter. The situation is the following.
I want to redirect some specific WP blog posts (permanently) from a subdomain to some specific pages on this WP main domain subdirectory. I'm using a WP Multi subdomain website. Here's what I mean:
sub1.domain.com/postname
needs to be redirected to:
domain.com/sub1/pagename
I can't figure out how to get this done. Here's how my WP htaccess- file that's located on the root of this subdomain normally looks like:
#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<Files 403.shtml>
order allow,deny
allow from all
</Files>
I hope someone can help me with this matter. It will truly help me. Thanks in forward!
Greets, Marc
Add the following HTTP_HOST rule just before your wordpress rules.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^postname/?$ http://domain.com/pagename [R=301,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
To redirect sub.domain.com to domain.com/subdir, you would use
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/subdir/$1 [R=301,L]

htaccess redirect to subfolder with exception

I've searched quite a lot without finding a solution.
I have a wordpress blog in /_wp and something else in /other
What I'm trying to is that every request gets redirected to the WordPress. Except those to /other and its child directories. I also want the access to the blog to be rewritten. Few examples to make it clear:
/ --> /_wp/
/ablogpost --> /_wp/ablogpost
/other --> /other
/other/bingou --> /other/bingou
I've tried a few things but what seems the most logical to me is:
don't touch the .htaccess of /_wp/ and of /other/
edit the .htaccess of the root '/' by adding:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mywebsite.com$
RewriteCond %{REQUEST_URI} !^(/other|/other/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ /_wp/$1
If you could tell me what is wrong there it would be great!
EDIT
After changing the index the subfolders were still not working here was my .htaccess back then:
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName site.com
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
EDIT 2
In the end it was a host problem thanks for your help though! Your answer works just well
You should follow this : http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
Your wordpress install is already in its own directory, so you just have to :
Copy /_wp/.htaccess to /.htaccess
Copy /_wp/index.php to /index.php
Edit /index.php :
require('./_wp/wp-blog-header.php');
Edit /.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Redirect Rule in htaccess for a folder

I have a wordpress hosting site www.mysite.com/myBlog . The wordpress installation is done inside public_html/www/myBlog folder inside my host folder.
I also have a folder public_html/www/myName which redirects me to a domain myName.com
Although this works fine but inside myName folder i have files like index.html. acad.html, worexp.html
clicking on them i expect a behavior like
myName.com/index.html
myName.com/acad.html
myName.com/workex.html
though i get it as myname.com only.
I found htaccess rules in myName folder as :
Redirect http://mydomainName.com/myName/+
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^mydomainName.com$
RewriteRule ^/?$ "http\:\/\/www\.mydomainName\.com\/myBlog" [R=301,L]
Can anyone help me with whats wrong with the htaccess file ?
More details:
My WordPress blog has something messed up. I can go to my blog and homepage works fine but when i try to go to any post it throws an 403 error. Apache forbidden.
Tried talking to web host for permissions its ok.
checked htaccess. Replaced code by default code stil not working.
Removed permalinks to default deleted htaccess created new permalinks.
Gave permissions to all the files in blog directory
Rewrote robots.txt Blog url is : www.windowsvj.com
Wordpress community is not able to suggest something very helpful too.
Current Redirect rule code in .htaccess is :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpblog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpblog/index.php [L]
</IfModule>
# END WordPress
This could be the result of FollowSymLinks being disabled in the server configuration. Simply adding Options +FollowSymlinks to the .htaccess file could do the trick.
Instead of using the flag [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpblog/
RewriteRule ^index\.php$ - [L] <---
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpblog/index.php [L] <---
</IfModule>
# END WordPress
Try using [QSA]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpblog/
RewriteRule ^index\.php$ - [QSA] <---
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpblog/index.php [QSA] <---
</IfModule>
# END WordPress
How [L] works is if the RewriteRule matches
RewriteRule . /wpblog/index.php [L]
Then all other rewrites after this RewriteRule are ignored as stated on the Apache website
"In most contexts, this means that if the rule matches, no further rules will be processed." http://httpd.apache.org/docs/current/rewrite/flags.html
Here is a link with more information on .htaccess flags
http://httpd.apache.org/docs/current/rewrite/flags.html
Hope this works for you :P

Resources