0

I am self learning php and started some coding for a web portal. I would like to develop the portal with url that should look like index.php?page=dashboard. If i put the dashboard.php in browser, it should not be displayed.

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. How to make the url look like from www.example.com/index.php?page=dashboard to www.example.com/dashboard
3
  • 2
    You should google for .htaccess and how to get what you want. Then you can come back to show us what you have tried and the issues you are facing. Commented Apr 28, 2015 at 16:27
  • @LelioFaieta The way I understand it he wants to know how PHP dynamic pages works AND rewriting. how to program to use pages like index.php?page=dashboard rather that having seperate php files like dashboard.php That's not just rewriting. That is basic php. Commented Apr 28, 2015 at 18:35
  • @PanamaJack you are right sir. Can you give me some good examples? Commented May 21, 2015 at 9:02

3 Answers 3

1

I think reading this wiki article on URI components may help you in understanding parts of the URL.

Just in brief,

  • ? denotes query/search send to server usually to query a database
  • # denotes fragment or partials, not sent to server and is read by client side only.

If you can correct the question or with better examples to make it clearer.

ie. index.php?dashboard is not valid.

Hope this helps.

UPDATE Pedro Lobito has given a solution below, which hopefully is what you are asking.

Sign up to request clarification or add additional context in comments.

1 Comment

@adrian-the, nice of you mentioning my answer. +1 for that and your explanation.
0

You can use apache mod_rewrite for that, i.e.:

Create a file named .htaccess on the root of your website and put the following contents:

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.

2 Comments

But i have lot of pages like this. Do i have to do it in htaccess for all the pages?
You're welcome. You can use a regex for that. Google htaccess regex tutorial.
0

You can make a new folder on your server/local and do a new index.html/index.php into it, so if a user opens www.example.com/dashboard/ it shows the url in the index but the user is on the index page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.