Tag Info

Hot answers tagged

3

What I've found to make this work: rewrite ^/foobar http://www.youtube.com/watch?v=oHg5SJYRHA0 redirect; You only need to do this: rewrite (?i)^/foobar http://www.youtube.com/watch?v=oHg5SJYRHA0 redirect; This just means prepend (?i) and otherwise everything is the same for matching.


3

Rewrite paths work differently inside a <Directory > context. The path you are matching is the full filesystem path with the current directory (including the trailing slash) removed. The effect of this is that you need to remove the leading slash from your regex and the replacement or move the rewrite rule outside the directory context where it will ...


3

Change break to last. Because the new URL will need to be processed by a different location, you need to have nginx restart processing for the new rewritten URL, which is only done when you use last in the rewrite rule. See the docs for a fuller explanation.


3

You can't match on a query string at all in a rewrite. So you'll need to check the argument directly. For instance: if ($arg_discount ~ ^free) { rewrite ^/join_trial /test2? permanent; } rewrite ^/join_trial /test? permanent; And I suspect you really do not want to be sending 301 redirects, as the user will then see /test or /test2 right in their ...


2

Satisfy. Your specific need is detailed in the Require docs as well. <Directory "/website/res/api"> Satisfy Any Allow from all </Directory> You will then need to duplicate any of the rewrite rules on the res.domain.com vhost. If you want the same content to be delivered from res.domain.com you may need to alias the ...


2

It looks like you've chained all the rules together with the [C] flag. See the documentation for an explanation of their meanings. You probably want [L] for "last" instead. It's also worth noting that the rules will be run until the URL does not change any longer; so your second-to-last rule will likely create a rewrite loop, unless you have a rule before ...


2

All our sites are setup in IIS with a single IP. 1) take an old desktop, run live linux distro, give it the same ip as the IIS box, do not connect it to network 2) fire up nginx on live linux box, and make the downtime page as you like it, test it by using an offline switch/hub connected to ur laptop 3) unplug IIS box ethernet cable, and plug it into ...


2

I also posted this question to StatusWolf's GitHub site, and the developer just got back to me. The cause of the problem is that I'm using a very old browser: StatusWolf is using 'window.location.origin' in the widget javascript to build the URL for loading files and making API calls. You're using an older version of Firefox (14.0.1, current is 26), ...


2

First of all, you specify a rule to match all requests (.*), then you add a condition for a specific url. You should have your limiting criteria in the match: <match url="^/foo_bar/(.*)" /> then you don't need the condition anymore. You use conditions only for additional criteria not based on the URL. Secondly {R:1} refers back to the whole url ...


2

If you change your rewrite to rewrite ^/(.*)/$ /snapshots/$1.html break; rewrite ^/(.*)$ /snapshots/$1.html break; then the first line will only match lines ending in a slash, and $1 will contain the full path minus the leading and trailing slashes. The second will catch the rest of the cases (that are working now).


2

This is nginx, not apache. You should avoid rewrites when possible (and it often is possible). Use try_files instead. For example: location /administration/ { try_files $uri $uri/ /administration/index.php?request=$request_uri; } location / { try_files $uri $uri/ /index.php?request=$request_uri; }


2

I prefer to return with a response code so the browser knows you are redirecting it to another URL. server { listen 80; server_name www.example.com; return 301 https://example.com$request_uri; } then another server configurations block for the https server { listen 443 ssl; server_name example.com; ... }


2

Above answer doesn't work any more for IE11 because string "MSIE" isn't available any more in user agent string. Sample IE11: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko Sample IE9: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)


2

Better use return instead of rewrite, because it's faster server { listen 80; server_name example.com; return 301 http://www.example.com$request_uri; server { listen 80; server_name www.example.com; [...] This way, we also send the client a proper status code, so that he asks the right domain in the next request. ...


1

You don't mention specific issues for each case, but in my experience the best thing to do, when trying to debug RewriteRules, is to turn on the rewrite log and crank up the rewriteloglevel. This will display the incoming request, and the pass/fail for each rule, as well as what it does with the request when it matches a rule. RewriteLog ...


1

Here's a pair of config files that I use for Zend Framework applications. First, php.conf, which I share between projects on my development workstation. I keep this at a directory above my sites directory, right in the nginx config root (e.g. /usr/local/etc/nginx/php.conf): fastcgi_intercept_errors on; # this will allow Nginx to intercept 4xx/5xx error ...


1

I had this question answered in another forum. This is a recap of that answer, for the record. The correct rewrite looks like this: <system.webServer> <rewrite> <outboundRules> <rule name="foo.com" enabled="true"> <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" ...


1

You're missing a try_files. location / { try_files $uri $uri/ /index.php; # ....everything else } You might also have a problem with the rewrite since you don't have a / at the beginning of the relative URL controllers/$1.php.... Try changing that to /controllers/$1.php.... And, you're missing a fastcgi parameter that tells php-fpm where to find ...


1

A location block needs a uri. So, you may want this: location / { rewrite "/[a-zA-Z]\w{1,9}/" /$1/auth/signin last; rewrite "/[a-zA-Z]\w{1,9}" /$1/auth/signin last; } Or, if you don't want to apply these rewrites to a certain path, just remove the location part altogether. I.e. rewrite "/[a-zA-Z]\w{1,9}/" /$1/auth/signin last; rewrite ...


1

There is a http://wiki.nginx.org/HttpSubModule - "This module can search and replace text in the nginx response." copy past from docs: Syntax: sub_filter string replacement Example: location / { sub_filter </head> '</head><script language="javascript" src="$script"></script>'; sub_filter_once on; }


1

We recently had a practical experience about this. See my answer here: http://stackoverflow.com/questions/1364673/apache-redirects-rewrite-maximum/18120886#18120886 I had the very same question recently. As I found no practical answer, we implemented an htaccess 6 rules of which 3 had 200,000 conditions. That means an htaccess file with the size of ...


1

To ensure that the testdir match is chosen instead of the jpg/txt match, use the following locations: location ^~ /testdir { deny all; return 404; } location ~* ^.+\.(jpg|txt)$ { root /var/www/site; } In your example, you have two types of locations. location /testdir is a prefix location, as it has no tilde (~) between location and /testdir. ...


1

Here is the code I use. It will accept any languages and country. # Tout pays de 2 digits et langue de 2 ou 3 digits ou juste la langue pas de pays - fonctionne bien et passe language et country #www.country.com/index.html devient www.country.com/index.php #www.country.com/fr/index.html devient www.country.com/index.php?language=fr ...


1

The Apache variable you want is called %{SCRI­PT_­FIL­ENAME}. In PHP's $_SERVER super global, both SCRIPT_NAME and SCRIPT_FILENAME exist but in Apache, only %{SCRIPT_FILENAME} exists. It's not clear from the documentation exactly what each of the PHP variables contains but in my testing, SCRIPT_FILENAME is a full filesystem path and SCRIPT_NAME is either ...


1

You can use SQUID, which is a more commonly used as a proxy, to accomplish what you are attempting. The url_rewrite_program option allows for requests to be sent to a script for rewriting. The following script would substitute the url in the manor you describe: #!/usr/bin/perl while (<>) { @line = split; $_ = $line[0]; if ...


1

You need to chain your RewriteRules using the C flag, as explained on the ServerFault page Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask? In your case, this would do: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !\.php$ RewriteRule ...


1

Add a query parameter to the redirect is the best option. It is done quite often for all kinds of reasons. For example make the rule like this: RewriteCond %{QUERY_STRING} !redirected RewriteRule /site/(\d+)/([^/]+)\.html /site/$2/$1?redirected [R=301,L] What now happens is that the redirects are to URLs with "?redirected" added to them. And so the rule ...


1

I think there are many ways to accomplish this (and likely opinions to go along with each) but I would do one of the two following: Separate the application into various websites within IIS Use separate folders with unique web.config files Use separate application pools so each can be restarted without affecting any other sites Use 3rd Party ...


1

You're doing it the hard way. Here's the easy way. server { listen 80; server_name example.com; rewrite ^(.*) http://www.example.com$1 permanent; } server { listen 80; server_name www.example.com; #The rest of your configuration goes here# }


1

first thing you haven't set your root - directive correctly -> thats why you get a 404 -> thats why all requests are redirected to your @dynamiccycletour (openstreetmap?) btw, whats the difference between /tile/ and /tile/SteveCountryVic/ ? so we need a little cleanup here first: server { .... # define where to find files # be sure to have it ...



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