简体   繁体   中英

.htaccess redirecting all routes to a file handling routes

I have little to none experience with .htaccess so I have a few questions in my head I want to clarify. I am attempting to make a website where all traffic redirects to my routing file which handles it. What I have in my mind is something like https://domain.smt/register will redirect to https://domain.smt/router.php?url=register . Is it possible to do so with the.htacess file or is there a better way of doing so?

There is a problem with this approach though, if I want to add parameters to my url, say https://domain.smt/register?redirect=page/category/stuff wouldn't the router file be vulnerable to injection attacks? How should I resolve this if I use this .htaccess approach? Or is this just not going to happen?

I have tried searching it and came across this Redirect all to index.php using.htaccess but it still doesn't mention the injection above so is it just me overthinking?

Thanks for any help.

You don't need that "url=" part in your router script. Set up .htaccess as explained in the mentioned question and then use $_SERVER['REQUEST_URI'] - it already contains the path.

Even easier, put phpinfo(); to the top of the router script and you'll see what variables are defined in it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM