I have my website with a sub-directory:
http://www.mysite.com/test/
Inside “test” directory I have:
index.php
included-inside-index-file.php
another-included-inside-index-file.php
script.php
Now, how can i rewrite url with .htaccess so it works like this:
http://www.mysite.com/test --> access index.php
http://www.mysite.com/test/beautiful-url --> access script.php?parameter=beautiful-url
http://www.mysite.com/test/included-inside-index-file.php --> 404 error
http://www.mysite.com/test/another-included-inside-index-file.php --> 404 error
This is pretty straightforward. You need a generic rule for the
beautiful-url, but preceded by rules which throw[R=404,L]for the scripts you want to hide.If you want to explicitly block direct access to
script.php, you can match it insideTHE_REQUEST. Place this after the rules which block access to the includes. I think this will work. If you tried to do it without theRewriteCond, you would get 404’s from the beautiful url rewrites.