dear programmers,
how to show urls
(http://example.com/mtfiles/2014/2014.html) from to (http://example.com/2014.html).
server at plesk panel
anybody please tell me . thank you

let me try this.. I must warn you before hand that the 2014.html must be changed to 2014.php else, it is not going to work.

What we are trying to do here is a simple router. This is similarly found in some MVC frameworks, but example below is approximately 1/10000 of what is the actual router. Jus to help you out.

First sTep: Create a file called .htaccess, paste the codes below and save it in the example.com directory.

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^.*$ ./index.php

What the codes above will do is to redirect all request to the index.php. index.php now will serve as the executor of our made-up function. I will also provide you the function later on.

Step TWo: Create another file called index.php, paste the codes below and save it in the example.com directory ( normally, this is in public_html).

function process_url($file_location){

  $url_segments = array();

  $url_request  = $_SERVER['REQUEST_URI'];

  $url_segments    = explode("/", $url_request);

   $file_name = pathinfo($url_segments[3], PATHINFO_FILENAME);


   if(file_exists($file_location.$file_name.'.php')){

   return ($file_location.$file_name.'.php');

   }

   else{
   return false;

   }
  }

  ## now we define the actual page location
  $actual_file_location = './mtfiles/2014/';

  ## we call the function above
  $this_short_url =  ((process_url($actual_file_location) != false)? include(process_url($actual_file_location)) : 'page not available');

I need to make some short explanation on what I just did above. The url segments array split the url into segments. So, for the uri request http://example.com/2014.html $url_segments[3], will approximately give us the script name which is 2014.html. We further process this information, so that we can include the actual document located in /mtfiles/2014/ directory. I used exploded and pathinfo PHP functions to do this.

The function will check if the file exists in the actual file directory and if it is, the function will return that as string.

Just below the function, I called the function process_url() and providing the actual file location as param.

Step Three: open the mtfiles/2014 directory and create a new 2014.php file. To test it put something like this

<?php


    echo 'This is 2014.php file';

We can test it by directing the browser to http://example.com/2014.html

My example above does not conform with the PSR0, which is strictly intended for class and method loading, but that is the only solution I can come up today. I'm sure this will work out for you.

Feel free to modify the script as you see fit to your application..

good luck..

thank you so much sir . i will try..

I just noticed that you are on plesk. Holy Macaroni. My proposed solution may not even work.

sir, i just followed your steps as you said above and created 3 files.
.htaccess file http://pastebin.com/8bkRUVUc
and uploaded to root directory

index.php http://pastebin.com/J3yv4Jxz
and uploaded to root directory

2014.php http://pastebin.com/kbvu1Fsc
and uploaded to http://example.com/mtfiles/2014/ directory.

http://example.com/2014.php if i enter this url. i am getting not found error message. incase i use this http://example.com/mtfiles/2014/2014.php which displays 2014.php content.

i thought that .htaccess file was not supported. i have server at plesk panel.

please can you help me.

shall i use web.config file instead of .htaccess file

how it will be done in web.config can you please help me..

Honestly, the last time I have seen plesk parallel was 5 years ago. I can't even recall what is the httpd.conf and vhost equivalent for it. However, I am pretty sure there is some type of server configuration file that can enable rewrite_module.

Can you check with your host what modules are installed on your server as far as rewriting?

You've mentioned about the web.config file. Can you please let me know if you have PHP parser installed on your server? I just want to make sure.

Here is a very nice reference in working with web.config file as a url prettifier.

can you run this scripts on your server? save this as test.php

<?php

    echo 'Server Request URI .'.$_SERVER['REQUEST_URI'];

Direct your browser to test.php. and let me know what did you see.

The reason I am making you test it like this, because I might be able to write something that don't even need .htaccess, but I cannot guarantee that it will work.

ha installed. i got this message
Server Request URI ./test.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.