MyBB Community Forums

Full Version: Prettier URL's?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Why do the URL's have .html tag, are there any way for nginx to remove that?
You'll have to change the way links are generated in the core, as well as removing .html from the rewrite rules.
(2015-06-01, 12:26 AM)Josh H. Wrote: [ -> ]You'll have to change the way links are generated in the core, as well as removing .html from the rewrite rules.

Where is the "core"
You'll have to edit the file inc/init.php, from line 244 onwards: https://github.com/mybb/mybb/blob/featur...t.php#L242

This should only be attempted if you know what you're doing, as we do not officially support core modifications due to the large amount of extra work they can cause for us.
https://github.com/mybb/mybb/blob/featur...#L239-L258

Change that entire section from /inc/init.php to this:

/* URL Definitions */
if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && isset($_SERVER['SEO_SUPPORT']) && $_SERVER['SEO_SUPPORT'] == 1))
{
 $mybb->seo_support = true;
 define('FORUM_URL', "forum-{fid}");
 define('THREAD_URL', "thread-{tid}");
 define('POST_URL', "post-{pid}");
 define('PROFILE_URL', "user-{uid}");

}

If you're using Nginx as your HTTP server then you'll want to add this location block to your site config file:

location / {
		rewrite ^/(?i)thread-(.*)/(.*)$ /thread-$1 permanent;
                rewrite ^/(?i)user-(.*)/(.*)$ /user-$1 permanent;
		rewrite ^/(?i)post-(.*)/(.*)$ /post-$1 permanent;
		rewrite ^/(?i)forum-(.*)/(.*)$ /forum-$1 permanent;

		rewrite  ^/(?i)user-(.*)$  /member.php?action=profile&uid=$1& last;
	        rewrite  ^/(?i)thread-(.*)$  /showthread.php?tid=$1&  last;
                rewrite  ^/(?i)forum-(.*)$  /forumdisplay.php?fid=$1& last;
                rewrite  ^/(?i)post-(.*)$  /showthread.php?pid=$1&    last;

		port_in_redirect off;

		if ($request_method !~ ^(GET|POST)$ ) {
	        	return 403;
		}

		try_files $uri $uri/ =404;
	}
(2015-06-03, 09:59 PM)Marisa Wrote: [ -> ]https://github.com/mybb/mybb/blob/featur...#L239-L258

Change that entire section from /inc/init.php to this:

/* URL Definitions */
if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && isset($_SERVER['SEO_SUPPORT']) && $_SERVER['SEO_SUPPORT'] == 1))
{
 $mybb->seo_support = true;
 define('FORUM_URL', "forum-{fid}");
 define('THREAD_URL', "thread-{tid}");
 define('POST_URL', "post-{pid}");
 define('PROFILE_URL', "user-{uid}");

}

If you're using Nginx as your HTTP server then you'll want to add this location block to your site config file:

location / {
 rewrite ^/(?i)thread-(.*)/(.*)$ /thread-$1 permanent;
                rewrite ^/(?i)user-(.*)/(.*)$ /user-$1 permanent;
 rewrite ^/(?i)post-(.*)/(.*)$ /post-$1 permanent;
 rewrite ^/(?i)forum-(.*)/(.*)$ /forum-$1 permanent;

 rewrite  ^/(?i)user-(.*)$  /member.php?action=profile&uid=$1& last;
        rewrite  ^/(?i)thread-(.*)$  /showthread.php?tid=$1&  last;
                rewrite  ^/(?i)forum-(.*)$  /forumdisplay.php?fid=$1& last;
                rewrite  ^/(?i)post-(.*)$  /showthread.php?pid=$1&    last;

 port_in_redirect off;

 if ($request_method !~ ^(GET|POST)$ ) {
         return 403;
 }

 try_files $uri $uri/ =404;
 }

Cheers. Any idea why the user profiles is still the old url? (member.php?action=profile&uid=2)

Everything else works fine.

Also last post doesn't work.

http://domain.com/thread-136-lastpost

thats how it formats lol.. Sad