rasslstudio
rasslstudio

Reputation: 1

.htaccess rewrite with special url and IDs digits as parameters

I built my own mvc model.

Now I want to rewrite following url:

http://example.com/admin/index.php/Frontend/show?request[id]=24&request[lang]=33

to

http://example.com/24/33/

How is it possible to rewrite that url via .htaccess from root path?

I have tried:

RewriteEngine on
RewriteBase /admin/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php/Frontend/show?request[id]=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php/Frontend/show?request[id]=$1&request[lang]=$2 [L]

I get following error:

No input file specified.

Thank you!

Upvotes: 0

Views: 256

Answers (1)

jnovack
jnovack

Reputation: 8807

Issues:

  • You probably only want digits.
  • You are missing a final /
# Good
RewriteRule ^([0-9]+)/([0-9]+)/$ index.php/Frontend/show?request[id]=$1&request[lang]=$2 [L]

Secondly, this rule is WAY too wide.

# Bad
RewriteRule ^([^/]+)$ index.php/Frontend/show?request[id]=$1 [L]

Again, you probably want only digits and a final /.

# Good
RewriteRule ^([0-9]+)/$ index.php/Frontend/show?request[id]=$1 [L]

Finally, for best practices, use a prefix for a directory you will never use.

# Gooder
RewriteRule ^show/([0-9]+)/([0-9]+)/$ index.php/Frontend/show?request[id]=$1&request[lang]=$2 [L]

Upvotes: 0

Related Questions