: (nginx rewrite) add word on dynamic URL ending | word is repeated multiple in URL I'm really confused by the Nginx rewrite rules. I have searched and found a lot of threads for rewrite rules
I'm really confused by the Nginx rewrite rules. I have searched and found a lot of threads for rewrite rules but I don't get the required result...
I have this form of a link:
example.com/picture/587
should rewrite to:
example.com/picture/587-specialword
the number is dynamic and is changing from URL to URL and only the URLs with the word "picture" should be affected.
So I tried these:
rewrite ^/picture(.*) /picturespecialword permanent;
rewrite ^(.*)picture(.*)$ picturespecialword;
which do not work... and I'm getting this result which leads to an error:
example.com/picture/587specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword&specialword
So the word that has been added one time is added multiple times.
Is there any solution for this? What am I doing wrong?
More posts by @Candy875
1 Comments
Sorted by latest first Latest Oldest Best
rewrite ^/picture(.*) /picturespecialword permanent;
This would seem to result in a redirect loop since (.*) will match the redirected URL which then gets "specialword" appended again and again, etc.
You can avoid this loop by being more specific in your regex and only checking for what you need, ie. a number. Try something like the following:
rewrite ^/picture/(d+)$ /picture/-specialword permanent;
I assume you want an external redirect (ie. the URL in the address bar should change) and not an internal rewrite?
You will need to clear your browser cache before testing, since permanent (301) redirects are cached by the browser.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.