-3

If i have somesite.com/thisiswhatiwant, how can I transform that into a variable and process it, without using get vars? What should I google in the first place?

The idea is to create a dynamic page structure where that part of the url will populate variables in the page and be used to return dynamic page specific queries.

Is there a framework I can use that has a way to handle this easily?

If I use javascript for this, how should I handle it to not return any 404 errors but rather just pull a templating page and then use that part of the url for developing of the page?

Thank you!

Joricam
  • 77
  • 3
  • 15
  • You can pass a varibale as `youdomain.com/page=home` and then `$page=$_GET['page']` to get the value of the variable $page. On the basis of that you can navigate. Suppose your `domain.com` pointing to index.php then place a code to get `$page` variable using `$_GET` and use if...else condition to redirect page accordingly. another easy way is using global magic variable `PHP_URL_PATH` – BetaDev Dec 29 '16 at 23:59
  • 3
    You're a code sponge; do you know what a sponge does? People give their **FREE** time to help you. You should reward them by accepting the answers that solved your code problems. What do you think Stack is, a free coding service? Well sure, but hey......... you gain rep points also and people will trust you more. – Funk Forty Niner Dec 30 '16 at 13:16

3 Answers3

4

Here is how you parse the path of a url in PHP

$url = "http://somesite.com/thisiswhatiwant";
var_dump(parse_url($url, PHP_URL_PATH));
meda
  • 45,103
  • 14
  • 92
  • 122
  • I found the awnser thank you, I did not asked for code. The correct terminology is vanity URLs. They are static urls that behave like dynamic urls. Dynamic urls are urls with queries which is not what we want here. This tutorial will help. The solution is trough the .htaccess rules as i expected. The rest is basic php/db queries. I still do not know of a web app framework that makes this trivial to implement, but there must be. Here is the tutorial http://culttt.com/2011/11/16/how-to-make-vanity-urls-using-php-htaccess-and-mysql/ – Joricam Dec 30 '16 at 20:31
3

If i have somesite.com/thisiswhatiwant, how can I transform that into a variable and process it, without using get vars? What should I google in the first place?

That's simply getting the current URL and parsing it. (Which are pretty well covered in the linked questions).

You do need to get the server to execute the PHP first. This question about the front controller pattern explains that.

If I use javascript for this, how should I handle it to not return any 404 errors but rather just pull a templating page and then use that part of the url for developing of the page?

Assuming you mean client-side JavaScript: You can't.

JavaScript runs in the context of a webpage.

  1. Get page from server
  2. Parse HTML document
  3. Run JavaScript that page says to run

If you 404 at step 1 then everything stops and no JS runs.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I found the awnser thank you, I did not asked for code. The correct terminology is vanity URLs. They are static urls that behave like dynamic urls. Dynamic urls are urls with queries which is not what we want here. This tutorial will help. The solution is trough the .htaccess rules as i expected. The rest is basic php/db queries. I still do not know of a web app framework that makes this trivial to implement, but there must be. Here is the tutorial http://culttt.com/2011/11/16/how-to-make-vanity-urls-using-php-htaccess-and-mysql/ – Joricam Dec 30 '16 at 20:31
0

The correct terminology is vanity URLs. They are static urls that behave like dynamic urls. Dynamic urls are urls with queries which is not what we want here.

This tutorial will help.

The solution is trough the .htaccess rules as i expected.

The rest is basic php/db queries.

I still do not know of a web app framework that makes this trivial to implement, but there must be.

Here is the tutorial

http://culttt.com/2011/11/16/how-to-make-vanity-urls-using-php-htaccess-and-mysql/

Joricam
  • 77
  • 3
  • 15
  • I found the awnser thank you, I did not asked for code. The correct terminology is vanity URLs. They are static urls that behave like dynamic urls. Dynamic urls are urls with queries which is not what we want here. This tutorial will help. The solution is trough the .htaccess rules as i expected. The rest is basic php/db queries. I still do not know of a web app framework that makes this trivial to implement, but there must be. Here is the tutorial http://culttt.com/2011/11/16/how-to-make-vanity-urls-using-php-htaccess-and-mysql/ – Joricam Dec 30 '16 at 20:31