[英]PHP Url redirection on index.php
I am self learning php and started some coding for a web portal. 我正在自学php,并开始为Web门户进行一些编码。 I would like to develop the portal with url that should look like index.php?page=dashboard.
我想使用看起来像index.php?page = dashboard的url开发门户。 If i put the dashboard.php in browser, it should not be displayed.
如果我将dashboard.php放在浏览器中,则不应显示它。
Queries that i have. 我有查询。
1.how to program to use pages like index.php?page=dashboard rather that having seperate php files like dashboard.php 1.如何编程以使用诸如index.php之类的页面?page = dashboard而不是具有诸如dashboard.php之类的独立php文件
You can use apache mod_rewrite for that, ie: 您可以为此使用apache mod_rewrite ,即:
Create a file named .htaccess
on the root of your website and put the following contents: 在网站的根目录上创建一个名为
.htaccess
的文件,并将以下内容放入:
RewriteEngine On
RewriteRule ^dashboard$ /dashboard.php [L]
This way, when a user navigates to www.yoursite.com/dashboard
apache will redirect him to dashboard.php
without changing the url. 这样,当用户导航到
www.yoursite.com/dashboard
apache会将他重定向到dashboard.php
而无需更改URL。
I think reading this wiki article on URI components may help you in understanding parts of the URL. 我认为阅读有关URI组件的Wiki文章可能有助于您理解URL的各个部分。
Just in brief, 简而言之,
If you can correct the question or with better examples to make it clearer. 如果您可以更正问题或提供更好的示例来使其更清楚。
ie. 即。 index.php?dashboard is not valid.
index.php?dashboard无效。
Hope this helps. 希望这可以帮助。
UPDATE Pedro Lobito has given a solution below, which hopefully is what you are asking. 更新 Pedro Lobito在下面提供了一个解决方案,希望它是您所要的。
您可以在服务器/本地上创建一个新文件夹,然后在其中新建一个index.html / index.php,因此,如果用户打开www.example.com/dashboard/,则它会在索引中显示URL,但用户处于索引页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.