-2

I have a path like following

http://localhost/streamcola/watch/getvideo.php

I want to remove /getvideo.php and just want the following path

http://localhost/streamcola/watch

how can i do this.? I not rewriting my URL , i just want to remove extension only.

Malik Nabeel
  • 49
  • 13

4 Answers4

0

The effect you want to achieve is called url-rewriting.
This is ususally something your server does via configuration and thus differs depending on your server (e.g. apache2, nginx, tomcat etc.)
Please refer this Article as a startingpoint: https://en.wikipedia.org/wiki/Rewrite_engine

jbin
  • 166
  • 5
0

You need to apply "mod_rewrite" for your URLs. It cannot be done without modifying .htaccess file, or just rename getvideo.php to index.php when opening http://localhost/streamcola/watch it will redirect to index.php.

0

You can use a regular expression:

<?php
$subject = <your String>;
$pattern = '/(.*)\/.*\.php?/';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
?>

See: http://php.net/manual/en/function.preg-match.php

Edit: Sorry, i thought you had a string you want to modify.

PhilipB
  • 329
  • 2
  • 16
0

File name removal is complex but its possible, but i do this by removing the extension of the file, As my Filename is getvideo.php and i want http://localhost/streamcola/watch So i change my file name to watch.php and remove that .php extension This is done by creating a new file named .htaccess file. I place it with my watch.php file and code of that .htyaccess file is following

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

and hence i get my desired URL..

Malik Nabeel
  • 49
  • 13