Tag Info

Hot answers tagged

8

I believe that this website may help you greatly: http://regex101.com/r/uP4nT1


6

This is the standard nginx behaviour for this part of your configuration : location /upload { if ($http_referer !~ "^http://(.+\.)?foo\.com/"){ rewrite .*\.(jpe?g|gif|bmp|png)$ /nohotlink.gif break; } location ~ \.(php|sql|php3|php4|phtml|pl|py|jsp|asp|htm|shtml|sh|cgi)$ { deny all; } } Why? Let me clarify how ...


5

You don't. The web server is allowed to decode percent-encoded characters which don't decode to special characters before applying rewrite rules, and is allowed to decode the remainder of percent-encoded characters before passing the data to your web application. (See RFC 3986.) What you should be doing is applying the front controller pattern in your web ...


4

There's an apache module called mod_substitute that can do this. Here's a short example: <Location "/"> AddOutputFilterByType SUBSTITUTE text/html Substitute "s/uat.site.co.jp/jp.uat.site2uk.co.uk/ni" </Location> Or, when combined with mod_proxy: ProxyPass / http://uat.site.co.jp/ ProxyPassReverse / http://uat.site.co.jp/ Substitute ...


4

You have misunderstood the $request_filename variable. It represents the physical path mapped to the file considering root and alias directives values and the current URI being processed. So your error_page directive will internally redirect to a URI corresponding to a physical path that doesn't exist as it the same as the path tested to enter your if ...


3

With three rules you can match the example cases and following versions of the widgets: rewrite ^\/widget\/(v\d+)\/?(\?act=)?(.*)$ /widget/$1.php?act=$2 last; rewrite ^\/widget\/?$ /widget/index.php last; rewrite ^\/widget\/?(\?act=)?(.*) /widget/index.php?act=$2 last; I have written these using a online regexp tester but did not setup a test environment ...


3

Locations using regexs must use the operator ~ : location ~ ^/wp-(admin|login)\.php$ { return 444; } Read this part of the official documentation to understand how locations work and this other part to understand what's the processing order.


3

Try this block for the public location: location /public { if ($args ~ "^pid=(?<placepid>[0-9]+)$") { rewrite ^/places /index.php?url=places/view/$placepid last; } if ($args ~ "^q=(?<getq>.+)&l=(?<getl>.+)$") { rewrite ^ /index.php?url=search/index/$getq/$getl last; } if ($args ~ ...


3

As per http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule:- What is matched? In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html"). Your pattern is matching an exact URL of "docs". The actual URL is probably ...


3

nginx always requires the leading slash in the URI part of the rewrite, while Apache doesn't want it. Without seeing the complete configuration, this is just a guess what the problem might be. Try this: rewrite ^/([^/]*)/([^/]*)\.html$ /?cmm=$1&page=$2 last;


3

If you haven't restarted Apache, be sure to do that, but if you've already done so, you could try a global output filter that runs a custom PHP script to do your replacing just to see if that solves it for some reason. EDIT: based on your comment, it could be that substitute isn't working because the content is compressed. To turn off compression, add ...


3

location / is never used The problem you have is related to location precedence (emphasis added). nginx first searches for the most specific prefix location given by literal strings regardless of the listed order. [...] Then nginx checks locations given by regular expression in the order listed in the configuration file. The first matching expression ...


3

This rewrite rule will do the trick: rewrite ^/something/(.+)$ http://domain.com/anything/$1 permanent;


3

You should not use redirect for post. If you have to, you should use 307 code for post. A end-user may be prompted about redirection. W3C Specifications - RFC 2616 301 Moved Permanently If the 301 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be ...


3

In nginx, you won't use a rewrite for this at all. You would use try_files instead. For example: try_files $uri $uri/ /puppy/index.php; Or, more likely, try_files along with a named location to handle PHP scripts. This isn't something that should be done in isolation; it is an integral part of the entire server block and you should not consider it ...


3

Ok, solution by myself: Add file with pcre: virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf, pcre:/etc/postfix/virtual_alias_maps.cf In file: /^admin@(.*)/ admin@$1,webmaster@$1 Reload, done.


2

Unfortunately the only reasonable solution is to fix the application so that it generates correct URLs. All other solutions will cause subtle issues.


2

You should use another server block for the redirect. server { server_name *.domain.tld; listen 100.10.10.1; location /personal { rewrite ^ http://domain.tld/personal permanent; } } And then you should remove the location block from the other server block, and remove *.domain.tld from the server_name directive.


2

The nginx documentation for rewrite (http://nginx.org/en/docs/http/ngx_http_rewrite_module.html) states that unless you end the replacement string with a '?' all previous qstring vars are appended. This means you don't need to (and probably shouldn't be) adding your qstring vars to the replacement. Also I would be as specific as I could be on the location ...


2

The problem shown by your error log indicates that your location /forum/... is not being matched. location /forum/(images|language|sounds|templates|uploads|vendor|src\/modules|nodebb\.min\.js(\.map)?|stylesheet\.css|admin\.css) { alias /srv/minora.me/webservices/forum.minora.me/public/; } The problem I see here is that this isn't treated ...


2

This should work: map $loc $loc_text { 11337 bar; 11419 restaurant; } map $style $style_text { 15477 painting; } rewrite ^/art/kartiny/location/(?P<loc>\d+)/style/(?P<style>\d+)$ /art/kartiny/location/$loc_text/style/$style_text redirect; See also http://nginx.org/en/docs/http/server_names.html#regex_names


2

See here for the same issue in Apache - there, I recommended using an external program to handle the rewrite, since it's clunky to do it in native configuration. For nginx, the best approach might be to embed some perl in your configuration via ngx_http_perl_module - use perl_set to set a variable to a UTF-8-ified version of $r->uri, using the Encoding ...


2

Wouldn't the error_page directive do this for you you? For example something like this: server { ... error_page 404 /404page.html; ... location = /authreq.html { if ($allowed = 0){ return 404; } } }


2

Reading nginx's documentation and the PCRE library documentation can help you understand how rewrite and regex work. For your example you would need a location block wrapping two rewrite rules like this : location /browse { rewrite ^/browse/(\d+)$ http://serverA.mycompany.com/show_item.cgi?$1 [flag]; rewrite ^/browse/([A-Z]{2,4}-\d+)$ ...


2

You need the break flag added to the rewrite rule, so that processing stops, and as this is inside a location block processing will continue inside that block: rewrite ^/petproject/?(.*)$ /$1 break; Note I also added /? to the matching pattern so that you don't end up with double slashes at the beginning of the url.


2

The configuration has the usual problem that generally happens with nginx. That is, using root directive inside location block. Try using this configuration instead of your current location blocks: root /home/me/Documents/site1; index index.html; location /petproject { alias /home/me/pet-Project/website; } This means that the default directory for ...


2

server { ... rewrite ^/widget$ /widget/index.php last; rewrite ^/widget/$ /widget/index.php last; rewrite ^/widget\?act=list$ /widget/index.php?act=list last; rewrite ^/widget/\?act=list$ /widget/index.php?act=list last; rewrite ^/widget/list$ ...


2

You can add alias in apache virtualhost which can make your images accessible with same link. Alias /www/fg/ /var/www/fg/ Replace "/var/www/" with your DocumentRoot path.


2

There are several problems in your configuration. First, you are using root directive inside locations. This is most likely the reason for 404 errors. You should change the first location block to start like this: location /postfixadmin { alias /var/www/html/postfixadmin/; Then, you should remove the root directive from the first inner location ...


2

Try this <VirtualHost *:80> ServerName example.com ProxyPass / http://1.example.com:8888/ ProxyPassReverse / http://1.example.com:8888/ RewriteEngine On # RewriteLog /tmp/rewrite.log RewriteBase / RewriteCond %{HTTP_HOST} !^example.com$ RewriteRule !^/(.) ...



Only top voted, non community-wiki answers of a minimum length are eligible