Reputation: 187
I'd like to rewrite the following path https://example.org/app/my/index.php?param=/foo/bar/
to https://example.org/app/my/foo/bar
and retrieve $_GET['param']
in php using .htaccess
.
The parameter has to be modular so it can be any path. And I would like to keep the ability to add other parameter like https://example.org/app/my/foo/bar/?id=XY
The .htaccess
-file is in /app/my/
.
I already tried this, but it didn't worked out
RewriteEngine On
RewriteRule ^(app/my/[\w-]+)/([\w-]+)/?$ $1.php?param=$2 [L,NC,QSA]
Upvotes: 0
Views: 41
Reputation: 785058
You may use:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(app/my)/(.+)$ $1/index.php?param=$2 [L,NC,QSA]
Using RewriteCond %{REQUEST_FILENAME} !-f
to avoid matching app/my/index.php
or any other file inside that folder.
You may try this rule inside app/my/.htaccess
:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.+$ index.php?param=$0 [L,QSA]
Upvotes: 1