English 中文(简体)
gin子沉积规则
原标题:nginx rewrite rule under a subdirectory

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>

感谢

最佳回答

不要忘记,要取代根本的道路!

location /main/ {
   root /full/path/from/root/main/;
   try_files $uri $uri/ /index.php?$args;
}

我把字句放在我的东道方,用双管/主要字眼,然后在下一环境中工作:

location /main {
        index index.php;
        try_files $uri $uri/ /main/index.php?q=$uri;
}
root /path/to/webroot;
问题回答
location ^~ /main {
    root /var/www/domain.com/html/wordpress;
    index index.php;
    try_files $uri $uri/ /main/index.php;

    location ~ .php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass   unix:/run/php/php8.0-fpm.sock;
    }
}

You need to change the php8.0 to your current PHP version in use and the root /var/www/domain.com/html/wordpress to your root directory where the subdirectory main comes after subdirectory Wordpress.





相关问题
URL rewrite in IIS6 - Third party tools

I have collected the following api/sdk/whatever which provide modules for doing url rewriting in IIS 5/6/7. Some are free-open source and some require $. I haven t tried any of them. I would like to ...

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

ASP.NET Friendly URLs

In my research, I found 2 ways to do them. Both required modifications to the Application_BeginRequest procedure in the Global.Asax, where you would run your code to do the actual URL mapping (mine ...

Could I get by HttpModule the URL that contains * before?

My web-site is working under ASP.NET 3.5, IIS7, Integrated pipiline mode. My HttpModule is getting request to all resources, including URLs like this: http://my-site.com/address And I would support *...

Domains & Foreward Slash

This is rather difficult to explain so please bear with me. We will be hosting 4 websites on our server and the plan is to have each site sit under its own domain: site-a.com site-b.com sub1.site-b....

URL Mod-Rewrite

I currently have a working URL: http://example.com/security-services.php?service=fixed-camera-surveillance and then I have PHP say, $_REQUEST[ service ] to do some stuff... But I d like to ...

热门标签