How can I rewrite the URL to have application name + querystring? For example I have a web application with the following querystring
mywebsite/default.aspx?UserName=xyz
How can I have URL with the folllowing
mywebsite?xyz
I have managed to implement RewriteModule using HttpApplication on Begin_request event and currently I can use this query
http://mywebsite/?xyz
Is there a way to have the url without /?
try,
rewrite ^/default\.aspx\?UserName=(.*)$ /?$1 last;
Related
I have an angular + springboot app and would like to use Akamai as our CDN going forward. We have this setup in our current CDN.
If request uri does not contains extension, then rewrite the uri i.e. replace(‘/folder.*/‘ ,’folder/index.html’) and return the request.
Is there something similar that i can set up in Akamai?
For a site running Mediawiki, I have this config for clean URLs:
rewrite ^/wiki/([^?]*)(?:\?(.*))? /wiki/index.php?title=$1&$2 last;
This works fine except when the page title needs to have a question mark. For a URL like /wiki/Who_is_your_daddy%3F_It_is_me the correct rewritten URL is /wiki/index.php?title=Who_is_your_daddy%3F_It_is_me. However, Nginx is rewriting to /wiki/index.php?title=Who_is_your_daddy&_It_is_me.
What is the correct rewrite rule?
The query string is not part of the normalised URI that is processed by the rewrite directive's regular expression. However, the query string will be automatically appended to the rewritten URI, so you don't need to do anything to include the &action=edit part. See this document for details.
The %3F in the original request will be normalised to a ? by the time that rewrite is processing it. You will need to capture both sides of the ? to manually translate it back to %3F in the new query string.
You can use more than one rewrite statement, so that the case with and without a %3F are both handled correctly.
For example:
rewrite ^/wiki/(.*)\?(.*)$ /wiki/index.php?title=$1%3f$2 last;
rewrite ^/wiki/(.*)$ /wiki/index.php?title=$1 last;
I have
many pages which were indexed by search engines with crappy GET-parameter like _escaped_fragment_ (for more info about escaped fragments see more Yandex man page)
nginx as reverse proxy in front of many different frontend apps
So I need to get 301 redirect only for all these pages with some GET-parameter to the same pages but without any get parameters. For example
example.com/some/long/path?_escaped_fragment_=
should be 301-redirected to
example.com/some/long/path
I can do it by adding this logic to each frontend app or I can do it at nginx configuration. I prefer to use second variant.
Potential solution can include
using http rewrite module
using if in rewrite to check GET-params
using map module to define request uri path without args from $request_uri
I've fixed my initial issue in such manner
add below code to my http context to define request uri path without args from $request_uri (here we use map module)
map $request_uri $request_uri_path {
"~^(?P<path>[^?]*)(\?.*)?$" $path;
}
add below code to my server context to make 301 redirect from pages with _escaped_fragment_ in GET parameters to the same pages without any GET parameters (here we use rewrite module)
if ($args ~* "_escaped_fragment_") {
rewrite ^ $scheme://$host$request_uri_path? permanent;
}
And this works for me.
I'm new to nginx, and I'd like to know if there is a way to pass an edited request URL to a web server. For example, I may have a web server running (Let's say apache. Or Flask.). I want all requests to /foo/(.*)$ to go to my web server, but I want my web server to see them without the foo. But if the initial request didn't have the foo, it would go somewhere else completely.
A request to /foo/bar would be routed to my web server, which would see the request simply as "/bar". However, a request that originally was made to "/bar" would be handled differently entirely. (So I don't just want to redirect).
Is there any way to do this? My thinking is that I could use this to modularize and namespace applications I write, where I could write an application as if it were routing requests on root, but it would actually be buried deeper in my site.
Thanks!!
This should do the trick (untested):
location /foo {
rewrite /[^/](/.*) $1 break;
# Pass to web server, e.g.:
#proxy_pass http://127.0.0.1:8080;
}
Note that the regular expression within the rewrite will strip any sub-directory from the request; but only one sub-directory. You could also use:
rewrite /foo(/.*) $1 break;
Which is more readable and clearer but not as powerful. This is up to you and your regular expression skills.
How can I make URL rewrite rule for this url:
example.com/account/login.aspx
to this url:
me.example.com/login
So any request to the folder /account will rewrite to me.example.com. Also sub folders and file like /account/subfoler/file1.aspx will rewrite to me.example.com/subfolder/file1
I already set the DNS wildcard to the app and all subdomains will take to the same ip address. All I need is the url rewrite rule.
You can achive this in IIS 7.0 Url Rewrite
OR
Write your own handler to intercept incoming request
To achieve this you can implement the IHttpHandler and process the url redirection logic in t he ProcessRequest method
Here is a very good example http://www.codeproject.com/Articles/30907/The-Two-Interceptors-HttpModule-and-HttpHandlers