Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+6 votes
940 views
in Q2A Core by

I want to install Q2A on Subdomain Subdirectory (https://subdomain.xyz.com/qa) Or, Only main domain subdirectory (Like https://abc.com/qa). Everything works fine but first URL structure which require .htaccess not working.

What should be the .htaccess and Nginx Conf. Rule for first URL structire for working.

Q2A version: 1.8.6

2 Answers

–2 votes
by

Q2A must be installed on the subdomain subdirectory or on only the main domain subdirectory. The first URL structure that requires .htaccess does not work, however.

How should the .htaccess and Nginx configurations be. Rule for first URL structure before working.

0 votes
by
edited by

Rewriting requests to the first URL structure (with or without subdirectory) doesn't require a .htaccess file in Nginx. Configure the rewriting in your site config like this:

index index.php index.html index.htm;
location /qa {
    try_files $uri @question2answer;
}
location @question2answer {
    if (!-e $request_filename) {
        rewrite ^/qa/(.+)?$ /qa/index.php?qa-rewrite=$1 last;
    }
}
location ~* "^/qa/index\.php(/|$)" {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

The fastCGI section is just included for completeness, it's not related to the URL structure rewriting.

Notes:

  • Embedding the rewrite rule in the if statement ensures that URL structures 3 and 4 keep working.
  • Replace /qa with the correct subdirectory for your installation.
  • Replace the path to the FPM socket with the one appropriate for the PHP/FPM version you're using.

If your Q2A installation isn't in a subdirectory, simply omit the subdirectory from the config:

index index.php index.html index.htm;
location / {
    try_files $uri @question2answer;
}
location @question2answer {
    if (!-e $request_filename) {
        rewrite ^/(.+)?$ /index.php?qa-rewrite=$1 last;
    }
}

...