0

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]

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

2 Comments

But it works only with foo not with e.g. foo/bar/
.+ will match anything including /. May be you have some other conflicting rule. I suggest you to show your full .htaccess in question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.