<div dir="ltr"><div><div>Here is our nginx default configuration file.<br><br>server {<br>  server_name <a href="http://www.mydomain.com">www.mydomain.com</a>;<br>  return 301 $scheme://<a href="http://mydomain.com">mydomain.com</a>$request_uri;<br>}<br><br>server {<br>server_name <a href="http://mydomain.com">mydomain.com</a>;<br>#listen 80;<br>root /var/www/html/mydomain/public_html;<br>index index.php info.php;<br><br>access_log /var/log/nginx/mydomain/access.log;<br>error_log /var/log/nginx/mydomain/error.log;<br><br>        location ~ \.php$ {<br>                include fastcgi_params;<br>                fastcgi_split_path_info ^(.+\.php)(/.+)$;<br>                #fastcgi_pass unix:/var/run/php5-fpm.sock;<br>                fastcgi_pass  <a href="http://127.0.0.1:9000">127.0.0.1:9000</a>;<br>                fastcgi_index index.php;<br>                fastcgi_param SCRIPT_FILENAME $request_filename;<br>                }<br><br>        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)$ {<br>                add_header Access-Control-Allow-Origin <a href="http://mydomain.com">mydomain.com</a>;<br>                }<br><br>        location / {<br>                try_files $uri $uri/ /index.php?q=$request_uri;<br>                 autoindex off;<br>                rewrite ^/([^_]*)_([^_]*_.*)\.html /$1-$2;<br>                rewrite ^/([^_]*)_([^_]*)\.html$ /$1-$2.html redirect;<br>                #if (!-e $request_filename){<br>                #rewrite ^(.*)$ /index.php redirect;<br>                #}<br>                }<br><br>if ( $request_filename ~ /action/cycling/cycling-is-best-for-health ) {<br>rewrite ^ /action/cycling/cycling-is-best-for-health.html? permanent;<br>}<br><br><br>#Server HTTP End<br>}<br><br><br></div>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. <br><br></div>here is the test run of curl -i <a href="http://mydomain.com/action/cycling/cycling-is-best-for-health">http://mydomain.com/action/cycling/cycling-is-best-for-health</a><br><br><br>HTTP/1.1 301 Moved Permanently<br>Server: nginx/1.6.2<br>Date: Sat, 16 Apr 2016 07:10:33 GMT<br>Content-Type: text/html<br>Content-Length: 184<br>Location: <a href="http://mydomain.com/action/cycling/cycling-is-best-for-health.html">http://mydomain.com/action/cycling/cycling-is-best-for-health.html</a><br>Connection: keep-alive<br><br><html><br><head><title>301 Moved Permanently</title></head><br><body bgcolor="white"><br><center><h1>301 Moved Permanently</h1></center><br><hr><center>nginx/1.6.2</center><br><br><div>test run with ".html" at the end.  <br>curl -i <a href="http://mydomain.com/action/cycling/cycling-is-best-for-health.html">http://mydomain.com/action/cycling/cycling-is-best-for-health.html</a><br><br>HTTP/1.1 301 Moved Permanently<br>Server: nginx/1.6.2<br>Date: Sat, 16 Apr 2016 07:10:37 GMT<br>Content-Type: text/html<br>Content-Length: 184<br>Location: <a href="http://mydomain.com/action/cycling/cycling-is-best-for-health.html">http://mydomain.com/action/cycling/cycling-is-best-for-health.html</a><br>Connection: keep-alive<br><br><html><br><head><title>301 Moved Permanently</title></head><br><body bgcolor="white"><br><center><h1>301 Moved Permanently</h1></center><br><hr><center>nginx/1.6.2</center><br><br></div><div>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.<br><br></div><div>any advice would be highly appreciated. <br><br></div><div>Thanks,<br></div><div>Yousuf<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 15, 2016 at 9:35 PM, Francis Daly <span dir="ltr"><<a href="mailto:francis@daoine.org" target="_blank">francis@daoine.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, Apr 15, 2016 at 12:27:11PM +0500, Muhammad Yousuf Khan wrote:<br>
<br>
Hi there,<br>
<br>
</span><span class="">> Sorry for the mistake in a's and b's i was typing that in general because<br>
> the context was not the URL but the problem.<br>
<br>
</span>If you can show one specific url which does show the problem, then it<br>
makes it much easier to see what is going on.<br>
<br>
If you can also include one small but complete config file that shows<br>
the problem, that makes it much easier for someone else to repeat your<br>
experiment.<br>
<br>
(And sometimes, the act of making a small config that shows the problem,<br>
will show you what the fix is.)<br>
<span class=""><br>
> >Do note that "location /x" can match anything that starts with /x; and<br>
> >if a request for /x.html returns a redirect to /x.html, you've got a loop.<br>
><br>
> Yes , i have double checked but my redirection rules are not created wrong.<br>
> so i am sure no loop is happening there.<br>
<br>
</span>Part of the point of you asking the question, is that you do not know<br>
where the problem is.<br>
<br>
So usually, the best thing is to run a test nginx with your config, then<br>
remove as much as possible while still showing the problem. Maybe that<br>
config will just have two location{} blocks, and the loop will be obvious.<br>
<span class=""><br>
> BTW just to update you guys. i am using wordpress.<br>
><br>
> i am doing two redirections , one domain base and second URL base.<br>
><br>
> domain base is working fine however URL redirections are giving me issues.<br>
<br>
</span>Use "curl" to test your broken url and see what exactly is returned.<br>
<br>
Do something like<br>
<br>
  curl -i <a href="http://your-server/aaaa/bbbbbbbb" rel="noreferrer" target="_blank">http://your-server/aaaa/bbbbbbbb</a><br>
<br>
and you should get a http 301 response, with something in the Location:<br>
header.<br>
<br>
Then do "curl -i" against that url, and see if you get the loop.<br>
<br>
The *rest* of the headers may show that PHP was, or was not, involved<br>
in the redirections.<br>
<span class=""><br>
> could this be related to wordpress?<br>
<br>
</span>It could be.<br>
<br>
If the "curl" responses show that PHP is involved, then it probably is.<br>
<div class="HOEnZb"><div class="h5"><br>
        f<br>
--<br>
Francis Daly        <a href="mailto:francis@daoine.org">francis@daoine.org</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</div></div></blockquote></div><br></div>