Search code examples
phpapache.htaccessvirtual-directory

How to use virtual folder structure url


I have url like this

http://www.abcdef.com/somthing.php

i want use same file content but different url format like this

http://www.abcdef.com/exp/go/to/123

for this where i need to modify either php or htaccess file?


Solution

  • The .htaccess file

    for your example you'd use:

    RewriteEngine on
    Redirect ^/exp/go/to/123$ /somthing.php [L]
    

    The main reason you'd use the "/exp/go/to/123" URL structure is because the different elements can be used as variables to load the page in which case you could use:

    RewriteEngine on
    Redirect ^/exp/go/to/([0-9]+)$ /somthing.php:id=$1 [L]
    

    which will take the 123 off the url and pass it to the someting.php as an ID parameter.