skip to Main Content

I have the “public_html” folder and a subfolder called “login” with the index.php that asks for the username and password.

I need to protect the subfolder contents from malicious bot requests and I thought to redirect|rewrite all the request URIs that contain the “login/” string to the login index.php.

I wrote these lines in the .htaccess inside the public_html:

RewriteEngine on
RewriteRule %{HTTP_HOST}/login/(.*) /login/index.php [L]

But it doesn’t work because if I write www.mysite.com/login/js/tinymce/something.php it doesn’t rewrite anything.

2

Answers


  1. I have a similar rewriterule on a system I maintain.

    Can you try this and see if it helps?

    RewriteRule ^(.*/login) /login/index.php [L]
    

    In theory it should redirect everything that starts /login to the index.php file in that folder.

    Login or Signup to reply.
  2. Hmmm… maybe its a syntax error of the regular expression used in the configuration file, maybe try this:

    RewriteRule (login/.*) login/index.php [L]
    

    Also this site regexr.com is a amazing debugger for regular expression
    Image from the same case

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search