Nginx rewrite .aspx url to new Laravel route - laravel

I'm trying to migrate an aspx project to new Laravel Project.
I want to convert and redirect old site links to new site links.
If an user comes from Google or old links.
old url : /tr/detail.aspx=pageId=596
new url : /old-url/detail/596
I tried below code but nothing helped.
location / {
rewrite http://cu.test/tr/detail.aspx?pageId=(.*) http://cu.test/index.php?$query_string permanent;
try_files $uri $uri/ /index.php?$query_string;
}

server {
server_name cu.test;
listen 80;
location /tr/detail.aspx {
rewrite ^/tr/detail.aspx /old-url/detail/$arg_pageId last;
set $args "";
}
location ~* /old-url/detail/(\d+)$ {
return 200;
}
}

Related

How to rewrite url with try_files css, js file [ laravel + vue-cli nginx]

I'm using vue-cli for frontend and Laravel for backend
Here is my Nginx config:-
server{
// Here I set up laravel in root project
listen 80;
root /var/www/html/serverside/public;
index index.php index.html index.htm;
server_name localhost;
//Here is vuejs project
location / {
root /var/www/html/frontend;
try_files $uri $uri/ = /index.html;
}
//Here is example when I want to use route path in laravel project
location /admin {
try_files $uri $uri/ /index.php?$query_string;
}
}
The Problem is assets() in Laravel redirect to /var/www/html/frontend;
How can I make asset in Laravel redirect in /var/www/html/serverside/public;
I try to do something like this:-
// if enter /admin-js I want to read app.js file but it didnt working
location /admin-js {
rewrite ^/admin-js/$ /var/www/html/serverside/public/js/app.js;
try_files $uri $uri/ /index.php?query_string;
}

Nginx configuration for angular and magento

I want to do nginx setup for handing two project with same domain.
Example domain: example.com
Angular project should run with example.com
magento2 project should run with example.com/shop
I tried the code below, but its not working.
location /shop {
alias /var/www/www.example.com/shop/;
index index.html;
try_files $uri $uri/
autoindex on;
}
Can please someone help me to do this.
You should use official NGINX configuration sample as provided here.
Naturally, you will prefix all the Magento 2 locations with /shop/, for your specific case.
So you will end up with this kind of config:
server {
listen 80;
server_name example.com;
location / {
root /path/to/your/generated/angular/resources;
try_files $uri$args $uri$args/ /index.html;
}
# Magento 2 directives start here...
location ~* ^/shop/setup($|/) {
# ...
}
# The rest of Magento 2 directives...
}
You can start with the following config to serve your Applications:
server {
listen 80;
server_name example.com;
location / {
root /path/to/your/generated/angular/resources;
try_files $uri$args $uri$args/ /index.html;
}
location /shop {
root /path/to/shop/;
index index.html;
try_files $uri $uri/;
}
}
I'm not 100% sure if the shop route will work. Maybe you need to configure php to serve it. Therefore you can follow this official example.
If you want to serve also to www.example.com you can set server_name *.example.com (docs).

nginx redirect all directories except one

I'm using nginx 1.0.8 and I'm trying to redirect all visitors from www.mysite.com/dir to google search page http://www.google.com/search?q=dir where dir is a variable, however if dir=="blog"( www.mysite.com/blog) I just want to load the blog content(Wordpress).
Here is my config :
location / {
root html;
index index.html index.htm index.php;
}
location /blog {
root html;
index index.php;
try_files $uri $uri/ /blog/index.php;
}
location ~ ^/(.*)$ {
root html;
rewrite ^/(.*) http://www.google.com/search?q=$1 permanent;
}
if I do this even www.mysite.com/blog will be redirected to google search page. If I delete the last location www.mysite.com/blog works great.
From what I've read here: http://wiki.nginx.org/HttpCoreModule#location it seems that the priority will be first on regular expressions and that first regular expression that matches the query will stop the search.
Thanks
location / {
rewrite ^/(.*)$ http://www.google.com/search?q=$1 permanent;
}
location /blog {
root html;
index index.php;
try_files $uri $uri/ /blog/index.php;
}
http://nginx.org/r/location
http://nginx.org/en/docs/http/request_processing.html
This situation can also be handled using only regex. Though this is a very old question and it has been marked answered, I'm adding another solution.
If you use multiple loop forwards using reverse proxy this is the easiest way without having to add a separate location block for every directory.
root html;
index index.php;
location / { #Match all dir
try_files $uri $uri/ $uri/index.php;
}
location ~ /(?!blog|item2)(.*)$ { #Match all dir except those dir items skipped
rewrite ^/(.*) http://www.google.com/search?q=$1 permanent;
}

nginx rewrite rule with try_files

At the bottom of this post is my current nginx rewrite rule and for the most part it is working as it should. The only issue I seem to be coming across is in the example of a link such as example.com/?action=cmd, this action is being processed as example.com/clientarea/?action=cmd
I am looking for a way that when the ? symbol is called that it will automatically append it to example.com/index.php instead of /clientarea/
location = / {
rewrite ^ /clientarea/ permanent;
}
location ~ ^(.*)$ {
try_files $uri $uri/ /index.php?$1;
}
Assuming you have a recent version of Nignx 1.0.x+ (I think), this should work:
location = / {
if ($is_args = '?') {
return 301 $scheme://$host/index.php$is_args$args;
}
rewrite ^ /clientarea/ permanent;
}
location ~ ^(.*)$ {
try_files $uri $uri/ /index.php?$1;
}

How do I rewrite mysite.com/page/ to mysite.com/page/index.html with NGINX?

How can I 301 rewrite mysite.com/page/ to mysite.com/page/index.html using nginx?
In Apache I had:
RewriteRule page/ http://mysite.com/page/index.html [R=301,L]
Thanks for help,
hydn
Try this settings:
location / {
rewrite /page/ http://mysite.com/page/index.html permanent;
...
}
I see from your comment to Sergiei that the '/page/' directory and '/page/index.html' does not actually exist and is rewritten elsewhere. So not surprising that Nginx gives a 404 not found.
What exactly should get served if a visitor requests '/page/index.html'? I.E., what does that get rewritten to?
If it is index.php?q=/page/index.html, then your config should be:
server {
# index directive should be in server or http block
# So no need to repeat in every location block
# unless specifically overriding it
index index.php index.html;
location / {
rewrite ^/page(/?)$ /page/index.html break;
try_files $uri $uri/ /index.php?q=$uri;
}
}
You could also use
server {
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
}
But there may be some issues with that. All depends on the detail of your application.

Resources