Here is our nginx default configuration file. server { server_name www.mydomain.com; return 301 $scheme://mydomain.com$request_uri; }
server { server_name mydomain.com; #listen 80; root /var/www/html/mydomain/public_html; index index.php info.php; access_log /var/log/nginx/mydomain/access.log; error_log /var/log/nginx/mydomain/error.log; location ~ \.php$ { include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.+)$; #fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; } location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|woff|woff2)$ { add_header Access-Control-Allow-Origin mydomain.com; } location / { try_files $uri $uri/ /index.php?q=$request_uri; autoindex off; rewrite ^/([^_]*)_([^_]*_.*)\.html /$1-$2; rewrite ^/([^_]*)_([^_]*)\.html$ /$1-$2.html redirect; #if (!-e $request_filename){ #rewrite ^(.*)$ /index.php redirect; #} } if ( $request_filename ~ /action/cycling/cycling-is-best-for-health ) { rewrite ^ /action/cycling/cycling-is-best-for-health.html? permanent; } #Server HTTP End } Thanks for your troubleshooting tip. the redirection rule is working great however but the.html link again redirection to the .html link. i can not get this thing. where is the second 301 rule once the link is redirected why again html is redirecting. here is the test run of curl -i http://mydomain.com/action/cycling/cycling-is-best-for-health HTTP/1.1 301 Moved Permanently Server: nginx/1.6.2 Date: Sat, 16 Apr 2016 07:10:33 GMT Content-Type: text/html Content-Length: 184 Location: http://mydomain.com/action/cycling/cycling-is-best-for-health.html Connection: keep-alive <html> <head><title>301 Moved Permanently</title></head> <body bgcolor="white"> <center><h1>301 Moved Permanently</h1></center> <hr><center>nginx/1.6.2</center> test run with ".html" at the end. curl -i http://mydomain.com/action/cycling/cycling-is-best-for-health.html HTTP/1.1 301 Moved Permanently Server: nginx/1.6.2 Date: Sat, 16 Apr 2016 07:10:37 GMT Content-Type: text/html Content-Length: 184 Location: http://mydomain.com/action/cycling/cycling-is-best-for-health.html Connection: keep-alive <html> <head><title>301 Moved Permanently</title></head> <body bgcolor="white"> <center><h1>301 Moved Permanently</h1></center> <hr><center>nginx/1.6.2</center> what i found out is that 2nd test on .html is again redirecting to .html. now what is causing this second redirection i have no clue. any advice would be highly appreciated. Thanks, Yousuf On Fri, Apr 15, 2016 at 9:35 PM, Francis Daly <fran...@daoine.org> wrote: > On Fri, Apr 15, 2016 at 12:27:11PM +0500, Muhammad Yousuf Khan wrote: > > Hi there, > > > Sorry for the mistake in a's and b's i was typing that in general because > > the context was not the URL but the problem. > > If you can show one specific url which does show the problem, then it > makes it much easier to see what is going on. > > If you can also include one small but complete config file that shows > the problem, that makes it much easier for someone else to repeat your > experiment. > > (And sometimes, the act of making a small config that shows the problem, > will show you what the fix is.) > > > >Do note that "location /x" can match anything that starts with /x; and > > >if a request for /x.html returns a redirect to /x.html, you've got a > loop. > > > > Yes , i have double checked but my redirection rules are not created > wrong. > > so i am sure no loop is happening there. > > Part of the point of you asking the question, is that you do not know > where the problem is. > > So usually, the best thing is to run a test nginx with your config, then > remove as much as possible while still showing the problem. Maybe that > config will just have two location{} blocks, and the loop will be obvious. > > > BTW just to update you guys. i am using wordpress. > > > > i am doing two redirections , one domain base and second URL base. > > > > domain base is working fine however URL redirections are giving me > issues. > > Use "curl" to test your broken url and see what exactly is returned. > > Do something like > > curl -i http://your-server/aaaa/bbbbbbbb > > and you should get a http 301 response, with something in the Location: > header. > > Then do "curl -i" against that url, and see if you get the loop. > > The *rest* of the headers may show that PHP was, or was not, involved > in the redirections. > > > could this be related to wordpress? > > It could be. > > If the "curl" responses show that PHP is involved, then it probably is. > > f > -- > Francis Daly fran...@daoine.org > > _______________________________________________ > nginx mailing list > nginx@nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx >
_______________________________________________ nginx mailing list nginx@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx