Right now I'm rewriting all http requests to Page.php with
rewrite ^ Page.php last;
But I want to allow to access file from /Ajax/ folder directly.
I tried adding (at the beginning)
rewrite /Ajax/SamplePage.php /Ajax/SamplePage.php last; (for example)
But still landed on Page.php
Is there any way to write something like
rewrite ^/Ajax/ - last;
?
You can try:
rewrite ^(?!(/Ajax/))(.*)$ /Page.php last;
Related
Please help me with nginx:
url www.server.com/products/customer/books
should be www.server.com/customer/products/books
So i need to swap /products/ with /customer/
Yes, you can do this with a rewrite. Add the following to your server block:
rewrite ^/customer/products/(.*)$ /products/customer/$1 last;
Or, if you have multiple URLs (ie customer & business), you can do this:
rewrite ^/(customer|business)/products/(.*)$ /products/$1/$2 last;
I have a single separate wordpress installation inside a subdirectory of another wordpress installation. Subdirectory's name is "blog" (This is not a multisite setup). My rewrite rules for nginx are:
location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ {
rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
# Rules for yoast sitemap with wp|wpsubdir|wpsubdomain
rewrite ^.*sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^.*/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
}
Sitemap is generated for both example.com/sitemap_index.xml and example.com/blog/sitemap_index.xml but both are same and do not contain posts of the second installation in subdirectory(blog). I understand this is related to rewrite rules configuration of subfolder but I am not able to figure out what exactly the problem is. I am using Yoast plugin and have installed Yoast plugins on both the installations i.e root and subfolder separately.
I got this working. So basically the problem was nginx rewrite rules which the lastest version of easy engine comes with. Since it is not accustomed by default for single wordpress installations in subdirectory, you need to modify these rules a bit.
so change:
rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
rewrite ^.*sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^.*/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
to
rewrite ^$dir1/sitemap\.xml$ $dir1/sitemap_index.xml permanent;
rewrite ^$dir1/([a-z]+)?-?sitemap\.xsl$ $dir1/index.php?xsl=$1 last;
rewrite ^$dir1.*sitemap_index\.xml$ $dir1/index.php?sitemap=1 last;
rewrite ^$dir1.*/([^/]+?)-sitemap([0-9]+)?\.xml$ $dir1/index.php sitemap=$1&sitemap_n=$2 last;
Where $dir1 is obviously your subdirectory which you can assign by checking it in location block.
I have a url directory path localhost/storage/app/media
I need it to be masked with both localhost/v/ and localhost/i/.
Nginx Sites-Available
This works for /v/, but if I make the same rules with /i/ it conflicts and shows a blank page with the message File not found. on all pages of the site.
# Mask storage media directory with /v/
rewrite ^/v(.*)$ /storage/app/media$1 last;
# Mask storage media directory with /i/
rewrite ^/i(.*)$ /storage/app/media$1 last;
You need to make your regular expression more specific. At the moment you are matching anything that begins with an i, for example, index.html. Try:
rewrite ^/v(/.*)$ /storage/app/media$1 last;
rewrite ^/i(/.*)$ /storage/app/media$1 last;
I would like to simplify those rewrite rules, don't know if this is possible, here is what I did :
rewrite ^/en/m/(.*)/$ /index.php?lang=en&cat=$1&platform=mobile last;
rewrite ^/en/(.*)/$ /index.php?lang=en&cat=$1 last;
rewrite ^/m/(.*)/$ /index.php?cat=$1&platform=mobile last;
rewrite ^/(.*)/$ /index.php?cat=$1 last;
it works but the number of rewrite rules is quite big..
The parameter /m/ (for mobile) is optional, is there a way to simplify that ? Any idea ?
I finally pass a single parameter and I parse it using php, it works like a charm, thank you Alexey!:)
How can I change a rewrite rule so that it affects only folder 01:
/01/01.png
/02/02.png
If is used one of this three rewrite rules
rewrite /(.*(png))$ /01/$1 last;
rewrite /(.*)$ /01/$1 last;
rewrite ^ /01/$uri last;
the file /01/01.png can be opened directly through /01.png (that was the goal of the rewrite rule) but now the file /02/02.png can't be opened any more as usually, nginx shows only "404 Not Found". Also png files in all other subfolders can't be opened any more. How the rewrite rule must be changed so that it affects only folder 01? I'm new to nginx and can't find a solution, please can anyone help?
I have found a solution for the problem, now I use a second rewrite rule for other folders with jpg-files. Many Greetings