Elliot
Elliot

Reputation: 83

How to treat one directory in a URL as a param?

I am sure that I need to use some rewrite condition for this, but I can't quite get my head around it.

As an example URL:

https://example.com/guest-area/{TENANT-NAME}/login

Here, {TENANT-NAME} should be treated as a GET param by PHP, so really the URL is treated as:

https://example.com/guest-area/login/?tenant={TENANT-NAME}

However, it should appear in the address bar as the first example and be accessible to the user like this.

The value of {TENANT_ID} will always come after /guest-area, so whatever is given in between the next set of forward slashes should be treated as $_GET['tenant'] and not a directory. Any directories after it (e.g. /login) are 'real' ones.

Upvotes: 0

Views: 49

Answers (1)

Ahmad Ameri
Ahmad Ameri

Reputation: 400

put this in your .htaccess

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^guest-area/(.*)/login /guest-area/login/?tenant=$1
RewriteRule ^guest-area/(.*)/login/ /guest-area/login/?tenant=$1

Upvotes: 1

Related Questions