skip to Main Content

I have a WordPress installation at mydomain.com/blogs and I have the following .htaccess

RewriteEngine On
RewriteBase /blogs/
RewriteBase /
RewriteRule ^index.php$ - [L]
ErrorDocument 404 /blogs/

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]


#RewriteBase /
#RewriteRule ^index.php$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule ./index.php [L]

# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blogs/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blogs/index.php [L]
</IfModule>

# END WordPress

Now everything works fine, but URLs like

mydomain.com/blogs/wp-content/plugins/

mydomain.com/blogs/wp-config.php

are not redirected to the 404 correctly. It is showing a blank white page. I need these files to be redirected to the 404 page. Please help.

2

Answers


  1. With your shown samples and attempts please try following .htaccess rules file. Apart from adding new rules added few FLAGs in to your existing rules also.

    Make sure to clear your browser cache before testing your URLs.

    RewriteEngine On
    RewriteBase /blogs/
    RewriteBase /
    RewriteRule ^index.php$ - [NC,L]
    ErrorDocument 404 /blogs/
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,NC,L]
    
    
    #RewriteBase /
    #RewriteRule ^index.php$ - [L]
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule . /index.php [NC,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [NC,L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [NC,L]
    RewriteRule ./index.php [NC,L]
    
    # BEGIN WordPress
    # The directives (lines) between `BEGIN WordPress` and `END WordPress` are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_rewrite.c>
    RewriteBase /blogs/
    RewriteRule ^index.php$ - [NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{THE_REQUEST} s/blogs/wp-content/plugins/?s [NC]
    RewriteRule . /blogs/index.php [NC,L]
    
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{THE_REQUEST} s/blogs/wp-config.php(?S+)?s [NC]
    RewriteRule . /blogs/index.php [NC,L]
    </IfModule>
    
    # END WordPress
    
    Login or Signup to reply.
  2. You could force a 404 redirect:

    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} ^/wp-config.php$
    RewriteRule .* - [L,R=404] 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search