I have been trying to delete ANY/ALL hyphens - and underscores _ from an incoming URL request to my nginx server.
So to be clear, when someone enters a URL as follows:
https://www.example.com/my-name_is-tom
...I need for nginx to rewrite the URL as follows:
https://www.example.com/mynameistom
I am working with the following config:
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name top.example.com;
ssl_certificate /etc/ssl/top.example.com.crt;
ssl_certificate_key /etc/ssl/top.example.com.key;
# set the root
root /srv/top.exemple.com;
index index.html;
location ~ ^/([a-zA-Z0-9=\?\_\-]+)$ {
rewrite ^(/.*)-(.*)$ $1$2 last;
rewrite ^(/.*)_(.*)$ $1$2 last;
rewrite ^/(.*)$ / break;
}
location / {
ssi on;
}
# BOSH
location /http-bind {
proxy_pass http://localhost:0000/http-bind;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
}
}
...however, I see no re-writing taking place.
Maybe I crafted that location rewrite thing wrong?
Maybe I need to somehow rewrite the X-Forward-For $remote_addr; ???
Any insight / suggestions would be MUCH appreciated -- I just don't know much about nginx and regexp.
Thank you all in advance for any time and attention.
EDIT/PS. It seems that I need some kind of rule that removes non-alphanumerics from $request_uri. So this:
example.com/my-name-is-tom.html
would be visually re-written in the browser URL field to:
example.com/mynameistomhtml
I realize how totally odd this sounds, but... that's what needs to happen.
Any further insight would be tremendously appreciated. TY!