Nginx configuration for php mvc in sub directory

Posted January 20, 2019 2k views

Need to configure below rewrite rule in Sub-directory in nginx configuration. subfolder name is

location / {
rewrite ^/([^/]+)/$ /interview-category.php?hri_id=$1;
location /questions {
rewrite ^/questions/([^/]+)$ /hrinterview-forum.php?topic=$1;

any help thanks

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @dasa,

I’m not sure I quite understand the question, can you be a little more specific, do you wish to make a rewrite rule everytime is visited to somewhere else or the other way around?

Anyway, here are some suggestions.

location = / {
    rewrite ^ redirect;

This’ll just do requests specifically for the root. If you need to catch everything (redirect to, then you’ll need something more involved:

location /interview/ {
    # Empty; this is just here to avoid redirecting for this location,
    # though you might already have some config in a block like this.
location / {
    rewrite ^/(.*)$$1 redirect;