By paulstocks
I have http://mydomain.com/page/#! and I want to rewrite to http://mydomain.com/page
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
EDIT: I realized my initial answer on hashbang didn’t answer your trailing slash question.
To remove the trailing slash on ALL URLs: Add a rewrite directive to the server block of your nginx config file that looks for URL’s ending with a trailing slash and permanently redirects to the same URL without the slash:
server {
listen 80;
server_name mydomain.com;
rewrite ^/(.*)/$ /$1 permanent;
}
To remove the trailing slash on ONE URL:
server {
listen 80;
server_name mydomain.com;
rewrite ^/page/$ /page permanent;
}
Keep in mind nginx never actually sees the #! or “hashbang” part of the URL, and it may appear even when you do the above redirects if it is set via javascript.
@aha I currently have the redirect for a trailing ‘/’. What I need is to be able to remove it AND 'additional characters’. I have ‘/#!’ and its causing SEO issues
We are not generating these. I believe they are coming from Bing (though I’m not positive, SEO guy will be in later this am). Our backend (or frontend) didn’t make them. We are just trying to service SEO bot traffic. This particular app is written in Meteor, though I don’t believe that has any bearing on the genesis of the routes. There was an old website (same domain) that did generate a bunch of routes we handle with rewrites … and maybe this is coming from some old cache … Thanks a bunch for your original post it was most helpful in understanding NGIX rewrites as the docs are painful to read!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.