2

I want do a redirect from old url:

http://example.org/xxxxxxxxx.html

To new urls (remove ".html")

http://example.org/xxxxxxxxx

How I can do this with nginx?

EDIT:

xxxxxxxxx can be differ, example:

http://example.org/url-1.html redirect to http://example.org/url-1 http://example.org/another-url.html redirect to http://example.org/another-url

2
  • op, did my answer satisfy your question? if yes, please upvote and accept! if no, feel free to provide clarifications of where it falls short, if it does. Commented Jul 6, 2016 at 3:26
  • thanks for accept&&upvote, +1 your way! Commented Jul 11, 2016 at 16:33

3 Answers 3

4
location ~ ^(.*)\.html$ {
    return 301 $1;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Probably you need a rewrite statement

location /xxx.html {
   rewrite ^/xxx(.*) http://example.org/xxxxx permanent;
 }

You detailed explanation please refer https://www.nginx.com/blog/creating-nginx-rewrite-rules/

Another method would be return directive

server {
    listen 80;
    listen 443 ssl;
    server_name www.old-name.com old-name.com;
    return 301 $scheme://www.new-name.com;
}

1 Comment

@rpayanm try above methods in configuration and let me know if you face any issues.
0
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.org www.example.org;
    return 301 http://$server_name$request_uri;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.