nginx rewrite rule under a subdirectory
13,858
try to use this, and please don't forget to replace root path!
location /main/ {
root /full/path/from/root/main/;
try_files $uri $uri/ /index.php?$args;
}
I've set wordpress on my host in folder /main and got it's working with next settings:
location /main {
index index.php;
try_files $uri $uri/ /main/index.php?q=$uri;
}
root /path/to/webroot;
Author by
Admin
Updated on June 23, 2022Comments
-
Admin almost 2 years
I have a WordPress site running nginx under a sub-direcotry. how can i write rewrite rules in a sub-directory? or can anyone please convert this Apache rewrite rule? I searched everywhere about nginx rewrite rules but nothing worked!
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /main/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /main/index.php [L] </IfModule>
any help appreciated, thanks
-
Admin over 12 yearsthanks Sergei. but it didn't work and redirects to my domain root without pictures and css (domain.com) but WordPress site is in domain.com/main/
-
Sergei Lomakov over 12 yearsCould you please attach nginx.conf?
-
Admin over 12 yearsThanks, I've added the code to default.conf and restarted nginx but when i open my website, no image and css are loaded, it's just text and links redirect to the same page as domain.com/main. custom: /%postname%/
-
Sergei Lomakov over 12 yearsYou have to add root path for your virtual host inside server directive block.
-
Ryan almost 10 years@SergeiLomakov you'd be my here too if you have ideas about stackoverflow.com/questions/23645386/…! I still can't figure it out! Thanks!