Rewrite a path with htaccess to different urls, based on calling path

53 Views Asked by At

I've been struggling to redirect to two different urls (files) based on what is in the path of the calling url, ie:

example.com/rh/xxxxx/ -> user.php?a=xxxxx

example.com/rh/xxxxx/yyyyy/ -> record.php?a=xxxxx&b=yyyyy

Here's what I have so far, and it's not working.

RewriteCond %{REQUEST_URI} ^/rh/[^/]*/[^/]*/?$ [NC]
RewriteRule ^/rh/([^/]*)/([^/]*)/?$ record.php?a=$1&b=$2 [L,NC]

RewriteCond %{REQUEST_URI} ^/rh/[^/]*/?$ [NC]
RewriteRule ^/rh/([^/]*)/?$ user.php?a=$1 [L,NC]

Any help is much appreciated. Thanks

1

There are 1 best solutions below

0
RavinderSingh13 On

With your shown samples please try following .htaccess rules file. Please make sure to keep your .htaccess rules files along with record.php and user.php.

Make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##Rewrite rule for example.com/rh/xxxxx/yyyyy/ -> record.php?a=xxxxx&b=yyyyy
RewriteRule ^rh/([^/]*)/([^/]*)/?$ record.php?a=$1&b=$2 [L,NC]

##Rewrite rule for example.com/rh/xxxxx/ -> user.php?a=xxxxx
RewriteRule ^rh/([^/]*)/?$ user.php?a=$1 [L,NC]