1

I have added htaccess rules to rewrite url like following...

RewriteRule ^demo/$ demo.php [L,QSA]

This is working fine for me. Now issue is i want to block url for demo.php file. Like user can access only

www.example.com/demo/ (valid)
www.example.com/demo.php (not valid and want to block this url)

Please help me do this. Thanks,

1 Answer 1

1

You can use this rule:

RewriteCond %{THE_REQUEST} /demo\.php [NC]
RewriteRule ^ - [L,R=404]
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your quick reply. This will redirect to 404 page?
Anubhava, I read many of your posts where you said %{THE_REQUEST} is a secure and safe var, it doesnt loop and doesnt match the 2nd iteration of rewrite rule. but I am just curious Why does it not match the uri on second round of Rule processing?
It doesn't match in 2nd iteration because THE_REQUEST remains unchanged. So even if REQUEST_URI becomes /demo.php after OP's rewrite rule, THE_REQUEST will still be /demo
Anubhava there is something wrong here. after adding this rules i am not able access any file under /demo directory. it redirect me to 404
This rule will only block direct requests to /demo.php, there might be other rules also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.