perqedelius perqedelius - 1 year ago 74
PHP Question

htaccess redirect URL with sub directories to php file

I need to redirect a Specific root URL (in this example "test") with unknown sub directories to a php file.

example URL

I have tried with this .htacces code

RewriteRule ^test(/.*)?$ redirect.php?path=$1


I use this code to split the $path

$path = explode("/", $_GET['path']);

But when I run print_r on $path in my redirect.php file array 0 is empty

Array ( [0] => [1] => sub1 [2] => sub2 )

How can I get the full path in my array?

Answer Source

If you want to capture full path then use RewriteCond with REQUEST_URI variable:

RewriteCond %{REQUEST_URI} ^/(test(?:/.*)?)$ [NC]
RewriteRule ^ redirect.php?path=%1 [L,QSA]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download