Skip to content

nginx seo urls

Solved Configure
15 2 6.1k 1
  • wrote on last edited by phenomlab
    #1

    what do the cfg have to look like for seo url?

    Example: instead of

    index.php?page=home

    so

    /page/home

    server {
        listen       80;
        server_name  riekmedia.dev;
    
        root   /var/www/website;
        index  index.php index.html index.htm;
    
       location / {
        if ($request_uri ~ ^/(.*)\.html$) {
            return 302 /$1;
            }
        }
    
        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 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.

    wrote on last edited by
    #14

    @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;
    	}
    
    
  • what do the cfg have to look like for seo url?

    Example: instead of

    index.php?page=home

    so

    /page/home

    server {
        listen       80;
        server_name  riekmedia.dev;
    
        root   /var/www/website;
        index  index.php index.html index.htm;
    
       location / {
        if ($request_uri ~ ^/(.*)\.html$) {
            return 302 /$1;
            }
        }
    
        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;
        }
    
    }
    
    wrote on last edited by
    #2

    @riekmedia Can you provide more information as to the technology you are using to present this site - for example, WordPress, Joomla, Ghost, etc ?

    Thanks

  • @riekmedia Can you provide more information as to the technology you are using to present this site - for example, WordPress, Joomla, Ghost, etc ?

    Thanks

    wrote on last edited by RiekMedia
    #3

    @phenomlab said in nginx seo urls:

    @riekmedia Can you provide more information as to the technology you are using to present this site - for example, WordPress, Joomla, Ghost, etc ?

    Thanks

    Self-written cms the url only needs to be from z.b index.php?page=home to /page/home

    in Apache woked this for .htaccess

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?site/([a-zA-Z0-9]+)$ /index.php?site=$1
    
    
  • @phenomlab said in nginx seo urls:

    @riekmedia Can you provide more information as to the technology you are using to present this site - for example, WordPress, Joomla, Ghost, etc ?

    Thanks

    Self-written cms the url only needs to be from z.b index.php?page=home to /page/home

    in Apache woked this for .htaccess

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/?site/([a-zA-Z0-9]+)$ /index.php?site=$1
    
    
    wrote on last edited by
    #4

    @riekmedia Something like this should work (obviously it needs modification to match your environment)

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location /my-app {
        try_files $uri $uri/ /my-app/file.php?arg=$uri&$args;
    }
    location ~ \.php$ {
        try_files $uri =404;
    }
    
  • @riekmedia Something like this should work (obviously it needs modification to match your environment)

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location /my-app {
        try_files $uri $uri/ /my-app/file.php?arg=$uri&$args;
    }
    location ~ \.php$ {
        try_files $uri =404;
    }
    
    wrote on last edited by
    #5

    @phenomlab said in nginx seo urls:

    @riekmedia Something like this should work (obviously it needs modification to match your environment)

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location /my-app {
        try_files $uri $uri/ /my-app/file.php?arg=$uri&$args;
    }
    location ~ \.php$ {
        try_files $uri =404;
    }
    

    Thank you, I’ll try this right now

  • wrote on last edited by RiekMedia
    #6

    `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;
        }
    
    }
    
    
    wrote on last edited by
    #7

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

  • wrote on last edited by
    #8

    I had tried both and neither worked

  • I had tried both and neither worked

    wrote on last edited by
    #9

    @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)

    wrote on last edited by RiekMedia
    #10

    @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;
        }
    
    }
    ´´´´
    wrote on last edited by
    #11

    @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.

    wrote on last edited by RiekMedia
    #12

    @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

    wrote on last edited by
    #13

    @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.

    wrote on last edited by
    #14

    @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;
    	}
    
    
    wrote on last edited by
    #15

    @riekmedia that looks fine to me

  • phenomlab 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
  • Nodebb and emails

    Solved Configure nodebb
    27
    5 Votes
    27 Posts
    10k Views
    phenomlab
    @Panda it will use SMTP. In all cases, I never use any plugin to send email. I’ll always send it raw.
  • Opening links in nodebb widget

    Solved Configure nodebb
    6
    4 Votes
    6 Posts
    3k Views
    phenomlab
    A more efficient way of including this would be to not over complicate it and leverage a standard iframe (providing the CSP headers of the remote site permit this) like below <iframe src="https://www.classmarker.com/online-test/start/?quiz=gag66aea7922f0a5" width="700" height="800"></iframe> This works first time every time on your site as intended.
  • Test of youtube embeds

    Solved Configure nodebb
    14
    11 Votes
    14 Posts
    5k Views
    Sampo2910
    @phenomlab Perfect!!! Many thanks.
  • How to deploy WordPress.org Developer theme

    Solved Configure wordpress theme github
    4
    1 Votes
    4 Posts
    3k Views
    phenomlab
    @Hari the real issue here is that I don’t think it can be used as a theme for WordPress because of the dependencies it clearly has, including its own Web server. My view here is that this is designed to be a complete development environment outside of the WordPress core.
  • Email Server Settings

    Solved Configure mx entry
    25
    10 Votes
    25 Posts
    11k Views
    phenomlab
    @Onix said in Email Server Settings: If anyone has long-term experience with self-hosted SMTP + DNS set-ups that remain stable, would be great to hear which configurations worked best. I can help with this
  • 6 Votes
    36 Posts
    15k Views
    phenomlab
    @justoverclock said in Digitalocean step by step guide to nginx configuration: i’m learning And that’s the whole point of this site If you don’t learn anything, you gain nothing.
  • how to change flarum configuration from apache to nginx?

    Solved Configure flarum
    3
    0 Votes
    3 Posts
    1k Views
    phenomlab
    See https://sudonix.com/topic/226/issues-getting-flarum-to-work-on-new-host/28?_=1645013723672
  • nginx can't start again

    Moved Solved Configure nginx server error
    20
    2 Votes
    20 Posts
    6k Views
    phenomlab
    @elhana-fine Yes that will happen of course if you still choose to restart the NGINX service after making a change and the test fails. The test on it’s own will state the error and the line number allowing you to fix that first