0

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!

1 Answer 1

0

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

1 Comment

Thank you for your answer. I tried the last line of your code, but I still get the error No input file specified (f.e. if I type in the URL example.com/show/24/33/) Is it possible that some apache configuration do not allow me to rewrite? Maybe it is important to know that my index.php file is under the directory /admin/ , so my RewriteBase is /admin/. My .htaccess is in the root directory.

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.