skip to Main Content

I need to set the redirect in htaccess.
My htaccess is given below

RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . frontend/web/index.php

So it redirects all requests to frontend/web/index.php

But the problem is that Suppose the following request comes /site/about
Currently using the above rules frontend/web/index.php is not receiving the path parameters. ie. /site/about is redirecting to

I need the path parameters as path parameters itself in frontend/web/index.php

.ie. /site/about should be mapped to /frontend/web/index.php/site/about
Also the path portion is dynamic. ie it can be anything like site/service

How can I do that rule in htaccess. I have checked some other solutions but most of them says to map path parameters to query strings which I cannot do as per my site settings.

2

Answers


  1. You’ll need to append the original path to the new one:

    RewriteRule (.*) frontend/web/index.php/$1
    
    Login or Signup to reply.
  2. As @Rickdenhaan said, You need to append the request path to your destination url. You can appened it using %{REQUEST_URI} variable or using a backrefrence at the end of your rewrite target.

    Change your RewriteRule line to this :

    RewriteRule . frontend/web/index.php%{REQUEST_URI} [L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search