-1

I get mysite.com/?file=abc

<?php if(!empty($_GET['file'])) {?>
<?php echo $_GET['file']; ?>
<?php } ?>

it's possible get value like this: mysite.com/file/abc

  • Yes, you should use a pretty URL in your project. – sajjad rezaei Feb 23 '22 at 21:55
  • 3
    if you are using **Apache** you'll need to use the **rewrite** module. the concept is sometimes called pretty url – medilies Feb 23 '22 at 21:55
  • Does this answer your question? [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – CBroe Feb 24 '22 at 09:17

1 Answers1

0

If you are using apache, and your config allows for htaccess overrides, you can create an .htaccess file like this

# Turn on URL rewriting
RewriteEngine On

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php?q=$1 [L]

URL

mysite.com/file/abc

In your php file do something like this

<?php
$query = explode('/', $_GET['q']);

if ($query[0] === 'file') {
   echo $query[1];
}
bumperbox
  • 10,166
  • 6
  • 43
  • 66