0

I am currently working on a website where pupils can create articles that can be commented by others.

I have a already developed a script that creates them and stores them in a mysql db.

Every one of these articles should be available under www.mydomain/articles/xyz/

but I don't want to create a new directory for everyone. So is it possible to pass the parameter article=xyz (www.maydomain/articles/articles.php&articles=xyz) to be shown as before mentioned?

I am sorry if my problem is too complex. If you have a question regarding it, do not hesitate to contact me! :)

Nidhi
  • 1,529
  • 18
  • 28
T. Smith
  • 15
  • 6

2 Answers2

1

Maybe you can do something like this with .htaccess file.
You can redirect every page to your index.phppage

<IfModule mod_rewrite.c>
    RewriteEngine On
    DirectoryIndex index.php
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule . /index.php [L]
</IfModule>

And then you can handle your domain in your php file:

<?php

/*
Example URL
$url = www.maydomain/articles/querystring/articles/xyz/param2/value2/param3/value3
$url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
*/

$url = "www.maydomain/articles/querystring/articles/xyz/param2/value2/param3/value3";
$url = explode("/querystring/", $url);

/*
Where $url[0] is (www.maydomain/articles),
and $url[1] is the rest of it (queryqtring/articles/xyz/param2/value2/param3/value3)
*/

// If you need you can include your page articles on your index page like this
$page_name = explode("/", $url[0]);
$page_name = end($page_name);
include("/path to your directory/". $page_name .".php");

$query_string = $url[1];
// And one more explode for query string:
$query_params = explode("/", $query_string);


for($i=0; $i<count($query_params); $i++)
{
    // odd value is GET name
    $key = $query_params[$i];
    // even value is GET value
    $value = (isset($query_params[$i+1])) ? $query_params[$i+1] : "";
    $_GET[$key] = $value;
    $i++;
}

echo "<pre>";
print_r($_GET);
echo "</pre>";

/*
// GET Output
Array
(
    [articles] => xyz
    [param2] => value2
    [param3] => value3
)
*/

?>
Nebojsa Nebojsa
  • 1,395
  • 1
  • 7
  • 19
  • @T.Smith Thing what you need is not quite simple. This is complete copy / paste solution. In your root folder make `.htaccess` file with my sample code, and put this php code on top of your `index.php` page, where `index.php` and `.htaccess` must be in same root folder. – Nebojsa Nebojsa Jun 05 '17 at 11:05
  • Okay, is it `.htaccess.txt`? – T. Smith Jun 05 '17 at 11:19
  • @T.Smith `htaccess` is an extension, not a file name, you have to create file without file name, such as "empty file name", "dot", "extension". If you are a windows user you can create file with empty name like this [stackoverflow link](https://stackoverflow.com/questions/5004633/how-to-manually-create-a-file-with-a-dot-prefix-in-windows-for-example-htacce) – Nebojsa Nebojsa Jun 05 '17 at 11:39
0

it can be achieved using htaccess,See this Tutorial for htaccess, this will guide you

https://codex.wordpress.org/htaccess

https://www.sitepoint.com/htaccess-for-all/

Krunal Limbad
  • 1,533
  • 1
  • 12
  • 23