Skip to content

nginx seo urls

Solved Configure
15 2 5.3k 1
  • `hm is not working 😕

    https://opensourceeducation.net/how-to-fix-seo-friendly-urls-in-nginx-for-wordpress-sites

    server {
        listen       80;
        server_name  localhost;
    
        root   /var/www/website;
        index  index.php index.html index.htm;
    
    
    ####Please add below lines for SEO Friendly URLs######################################
    	location / {
    		index index.php;
    		try_files $uri $uri/ /index.php?page=$uri&$args;
    	}
    ######################################################################################
    
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /var/www;
        }
            location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   unix:/var/run/php/php8.0-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    
    }
    
    
  • `hm is not working 😕

    https://opensourceeducation.net/how-to-fix-seo-friendly-urls-in-nginx-for-wordpress-sites

    server {
        listen       80;
        server_name  localhost;
    
        root   /var/www/website;
        index  index.php index.html index.htm;
    
    
    ####Please add below lines for SEO Friendly URLs######################################
    	location / {
    		index index.php;
    		try_files $uri $uri/ /index.php?page=$uri&$args;
    	}
    ######################################################################################
    
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /var/www;
        }
            location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   unix:/var/run/php/php8.0-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    
    }
    
    

    @riekmedia are you using this as a guide instead of the snippet I provided ?

  • I had tried both and neither worked

  • I had tried both and neither worked

    @riekmedia Is there any way I can get access to the server to investigate, or perhaps get a copy of the source code to fix locally ? (I’ll also need the database)

  • @riekmedia Is there any way I can get access to the server to investigate, or perhaps get a copy of the source code to fix locally ? (I’ll also need the database)

    @phenomlab Which database do they mean? I’m not talking about Nodebb but about the web server nginx. I had included the config.

    default.conf for Domain riekmedia.dev

    server {
        listen       80;
        server_name  riekmedia.dev;
    
        root   /var/www/website;
        index  index.php index.html index.htm;
    
    
    	location / {
    		index index.php;
    		try_files $uri $uri/ /index.php?page=$uri&$args;
    	}
    
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /var/www;
        }
            location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   unix:/var/run/php/php8.0-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    
    }
    ´´´´
  • @phenomlab Which database do they mean? I’m not talking about Nodebb but about the web server nginx. I had included the config.

    default.conf for Domain riekmedia.dev

    server {
        listen       80;
        server_name  riekmedia.dev;
    
        root   /var/www/website;
        index  index.php index.html index.htm;
    
    
    	location / {
    		index index.php;
    		try_files $uri $uri/ /index.php?page=$uri&$args;
    	}
    
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /var/www;
        }
            location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   unix:/var/run/php/php8.0-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    
    }
    ´´´´

    @riekmedia I mean a copy of the database that the CMS connects to, plus the source code. It’s hard to provide a fix without it.

  • @riekmedia I mean a copy of the database that the CMS connects to, plus the source code. It’s hard to provide a fix without it.

    @phenomlab there is no cms yet, I program the whole thing first. It is now just a small php website with subpages that are accessed via index.php?page=aboutus z.b. I just have to change the webserver now that it converts dynamic urls to seo urls

    example

    riekmedia.dev/index.php?page=aboutus

    new url

    riekmedia.dev/page/aboutus

    with apache you could solve this via htaccess with Rewrite Rule

    example

    # BEGIN RIEK-MEDIA
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^/?page/([a-zA-Z0-9]+)$ /index.php?page=$1
    </IfModule>
    # END RIEK-MEDIA
    

    Hier are example from page nginx not working

    https://riekmedia.dev/index.php?page=impressum

    https://riekmedia.dev/page/impressum

    Apache Server rewrite Rule is working

    https://myteamspeak.online/index.php?page=impressum

    https://myteamspeak.online/page/impressum

  • @phenomlab there is no cms yet, I program the whole thing first. It is now just a small php website with subpages that are accessed via index.php?page=aboutus z.b. I just have to change the webserver now that it converts dynamic urls to seo urls

    example

    riekmedia.dev/index.php?page=aboutus

    new url

    riekmedia.dev/page/aboutus

    with apache you could solve this via htaccess with Rewrite Rule

    example

    # BEGIN RIEK-MEDIA
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^/?page/([a-zA-Z0-9]+)$ /index.php?page=$1
    </IfModule>
    # END RIEK-MEDIA
    

    Hier are example from page nginx not working

    https://riekmedia.dev/index.php?page=impressum

    https://riekmedia.dev/page/impressum

    Apache Server rewrite Rule is working

    https://myteamspeak.online/index.php?page=impressum

    https://myteamspeak.online/page/impressum

    @riekmedia Ah, ok. That makes sense. I can probably replicate this fairly easily. Leave it with me. Hopefully should be back to you at some point later today.

  • @riekmedia Ah, ok. That makes sense. I can probably replicate this fairly easily. Leave it with me. Hopefully should be back to you at some point later today.

    @phenomlab that seems to work. Or unclean?

    ####Please add below lines for SEO Friendly URLs
    	location / {
    		index index.php;
    		rewrite ^/page(?:/([a-z]+))?$ /index.php?page=$1;
    	}
    
    
  • @phenomlab that seems to work. Or unclean?

    ####Please add below lines for SEO Friendly URLs
    	location / {
    		index index.php;
    		rewrite ^/page(?:/([a-z]+))?$ /index.php?page=$1;
    	}
    
    

    @riekmedia that looks fine to me

  • phenomlabundefined phenomlab has marked this topic as solved on

Did this solution help you?
Did you find the suggested solution useful? Support 💗 Sudonix with a coffee ☕
If your organisation needs deeper expertise around infrastructure, security, or technology leadership, learn more about Phenomlab Ltd. Many of the deeper technical guides behind Sudonix are published there.

Related Topics