本文介绍了有什么好的方法可以隐藏 url 的复杂性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP 和 TWIG 构建一个网站,我已将我的代码组织成:类文件夹:用于 php 类lib 文件夹:用于非类的 php 文件模板文件夹:用于树枝模板和 index.php 文件

i am building a web site using PHP and TWIG, i have organized my code into:class folder: for php classeslib folder: for non-classes php filestemplates folder: for twig templatesand index.php file

当我想包含注册页面的链接时,例如链接将是:域名/lib/register.php问题是:有没有什么好的方法可以从链接中隐藏文件组织例如,使链接类似于:域名/注册而不更改我的文件组织并保留在 url 中发送获取参数的能力?

when i want to include a link for register page for example the link will be: domain-name/lib/register.phpthe question is: is there any good way of hiding the file organization from the link for example to make the link something like: domain-name/register without changing my file organization and preserving the ability to send get parameters in the url?

谢谢

推荐答案

这是我将使用的示例 htaccess 文件.在register/"之后输入的文件夹结构被视为转发到 register.php 的变量.如果需要,QSA 标志将允许您将其他 GET 变量视为变量.(例如/register/something/?some_var=1).

Here's an example htaccess file I would use. Folder structures entered after "register/" are treated as variables that forward to register.php. The QSA flag will allow you to have additional GET variables treated as vars if need be. (e.g. /register/something/?some_var=1).

这是针对特定情况,当您知道要为哪些页面重写多少变量时.换句话说,以下仅适用于两个变量/点(例如/registers/var1/var2/).

This is for specific cases when you know how many variables you want to rewrite for what pages. In other words, the below will only work with two variables/spots (e.g. /registers/var1/var2/).

希望有帮助!

############################################
## ENABLE REWRITES
RewriteEngine on
Options +FollowSymLinks

## EXAMPLE WITH 1 VAR
RewriteRule ^register/([A-Za-z0-9-]+)/ lib/register.php?var1=$1 [L,QSA]

## EXAMPLE WITH 2 VAR
RewriteRule ^register/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/ lib/register.php?var1=$1&var2=$2 [L,QSA]

## ALSO GOOD TO HAVE ERROR DOCS REWRITE
ErrorDocument 404 oops/

这篇关于有什么好的方法可以隐藏 url 的复杂性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 07:01