Sajjad Dehghani
Sajjad Dehghani

Reputation: 640

How to check URL to contain special characters on .htaccess

I need to redirect all URLs that contain /../ or /../../* string match to 403 page with .htaccess config.

For example when user type https://example.com/index.php/../../js/sample.js on browser URL, I need to redirect to 403 Forbidden page and just https://example.com/js/sample.js URL is valid, I need to prevent access Js and other directories and files like ../../ on URL.

Upvotes: 0

Views: 364

Answers (2)

Sajjad Dehghani
Sajjad Dehghani

Reputation: 640

Finally i use this rule to achieve my question answer, I hope to help you if you have same question:

RewriteCond %{THE_REQUEST} ^.*/\.\./ [NC]
RewriteRule ^ /404.php [L]

Upvotes: 0

ewwink
ewwink

Reputation: 19164

RewriteEngine On
RewriteRule ^.*/\.\./ - [R=403,NC,L]

will match

https://example.com/index.php/../js/sample.js
https://example.com/index.php/../../js/sample.js

Upvotes: 1

Related Questions