Problem in change URL and remove a phrase in Nginx
by aria_redhat from LinuxQuestions.org on (#5HNX7)
Hello. Previously my site URL was as follows and there was an extra "forum" word at the end of the URL:
Code:https://mysite.com/forums/forum
I managed to remove the word "forum" from the end of the URL using the following rewrite, and my URL became https://mysite.com/forums.
Code:rewrite ^/forums/forum$ https://mysite.com/forums permanent;
There are now a number of other old URLs that do not work with rewrite above. For example, the following address:
Code:https://mysite.com/forums/forum/%D8%A8%D8%AE%D8%B4-%D8%A2%D9%85%D9%88%D8%B2%D8%B4-2210
The "forum" phrase in the middle of the url should be removed and then converted to the following address:
Code:https://mysite.com/forums/%D8%A8%D8%AE%D8%B4-%D8%A2%D9%85%D9%88%D8%B2%D8%B4-2210
But this does not happen. I also put the following rewrites in the Nginx configuration file but the "forum" phrase is still in the middle of my urls.
Code:rewrite ^/forums/forum$ https://mysite.com/forums(.*)$1 last;
rewrite ^/forums/forum$ https://mysite.com/forums$1 last;
rewrite ^/forums/forum(.*)\.html$ /forums(.*)$1 last;
rewrite ^/forums/forum(.*)$ /forums(.*)$1 last;
Where is the problem and how can I remove this word "forum" from the middle of my URLs?
Code:https://mysite.com/forums/forum
I managed to remove the word "forum" from the end of the URL using the following rewrite, and my URL became https://mysite.com/forums.
Code:rewrite ^/forums/forum$ https://mysite.com/forums permanent;
There are now a number of other old URLs that do not work with rewrite above. For example, the following address:
Code:https://mysite.com/forums/forum/%D8%A8%D8%AE%D8%B4-%D8%A2%D9%85%D9%88%D8%B2%D8%B4-2210
The "forum" phrase in the middle of the url should be removed and then converted to the following address:
Code:https://mysite.com/forums/%D8%A8%D8%AE%D8%B4-%D8%A2%D9%85%D9%88%D8%B2%D8%B4-2210
But this does not happen. I also put the following rewrites in the Nginx configuration file but the "forum" phrase is still in the middle of my urls.
Code:rewrite ^/forums/forum$ https://mysite.com/forums(.*)$1 last;
rewrite ^/forums/forum$ https://mysite.com/forums$1 last;
rewrite ^/forums/forum(.*)\.html$ /forums(.*)$1 last;
rewrite ^/forums/forum(.*)$ /forums(.*)$1 last;
Where is the problem and how can I remove this word "forum" from the middle of my URLs?