Question

I am trying to set my Nginx server to igonre if the visitors use lower or upper case in the address . For example, i want that both www.mydomain.com/section and www.mydomain.com/Section point to the same directory.

I searched a lot to see if I could do it through vhost configuration, but I couldn't find.

Anyone?

My VHost configuration goes like that:

server {
## Your website name goes here.
server_name server.com;
## Your only path reference.
root /var/www/citeu;
listen 80;
client_max_body_size 40M;
## This should be in your http block and if it is, it's not needed here.
index index.php index.htm index.html;

include conf.d/drop;

    location / {
            # This is cool because no php is touched for static content
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location ~ \.php$ {
        fastcgi_buffers 4 256k;
        fastcgi_buffer_size 128k;
        fastcgi_intercept_errors on;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
        fastcgi_max_temp_file_size 50M;


    }

        # BEGIN W3TC Page Cache cache
location ~ /wp-content/w3tc/pgcache.*html$ {
    add_header Vary "Accept-Encoding, Cookie";
}

location ~ /wp-content/w3tc/pgcache.*gzip$ {
    gzip off;
    types {}
    default_type text/html;
    add_header Vary "Accept-Encoding, Cookie";
    add_header Content-Encoding gzip;
}
# END W3TC Page Cache cache
# BEGIN W3TC Browser Cache
gzip on;
gzip_types text/css application/x-javascript text/x-component text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location ~ \.(css|js|htc)$ {
}
location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
}
location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
}
# END W3TC Browser Cache
# BEGIN W3TC Page Cache core
rewrite ^(.*\/)?w3tc_rewrite_test$ $1?w3tc_rewrite_test=1 last;
set $w3tc_rewrite 1;
if ($request_method = POST) {
    set $w3tc_rewrite 0;
}
if ($query_string != "") {
    set $w3tc_rewrite 0;
}
if ($http_host !~ "server.com") {
    set $w3tc_rewrite 0;
}
set $w3tc_rewrite3 1;
if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|\/feed\/|wp-.*\.php|index\.php)") {
    set $w3tc_rewrite3 0;
}
if ($request_uri ~* "(wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php)") {
    set $w3tc_rewrite3 1;
}
if ($w3tc_rewrite3 != 1) {
    set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(comment_author|wp\-postpass|wordpress_\[a\-f0\-9\]\+|wordpress_logged_in)") {
    set $w3tc_rewrite 0;
}
if ($http_user_agent ~* "(W3\ Total\ Cache/0\.9\.2\.4)") {
    set $w3tc_rewrite 0;
}
set $w3tc_ua "";
set $w3tc_ref "";
set $w3tc_ssl "";
set $w3tc_enc "";
if ($http_accept_encoding ~ gzip) {
    set $w3tc_enc _gzip;
}
set $w3tc_ext "";
if (-f "$document_root/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl.html$w3tc_enc") {
    set $w3tc_ext .html;
}
if ($w3tc_ext = "") {
  set $w3tc_rewrite 0;
}
if ($w3tc_rewrite = 1) {
    rewrite .* "/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl$w3tc_ext$w3tc_enc" last;
}
# END W3TC Page Cache core

}

Was it helpful?

Solution 2

Your problem isn't with the hostname, it's with the location block and filename.

In terms of location blocks, you can do a case insensitive match with this operator ~*

Most filesystems are case sensitive, so if the file you are serving is real... you're likely to have an issue.

most people do something like this:

  • ensure everything is lowercase
  • use a try_files files directive to fail onto a php script that simply redirects to an entirely lowercase url

there's a 3rd party library that can do lowsercase string conversions ( http://wiki.nginx.org/3rdPartyModules )

OTHER TIPS

I also found another temporary solution.

I used:

 location ~ /Folder {
        rewrite ^/([^/]*)(.*)$ /folder;}

Just in case the visitor wants to access a specific folder I want him to access but typing a different letter case from the original folder. It is far from perfect solution, but I will use while I figure out how to use the module correctly.

the below worked for me ,to open (ibeacons.html) in capital or small letters

 location ~* /ibeacons.html {

 try_files $uri $uri/ /ibeacons.html;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top