Recently I broke ties with WordPress and migrated all of my site’s content to my own custom-made CMS. All works great except for one thing. All previous links to my site’s blog posts have a trailing slash. Since none of my current URLs have a trailing slash, the previous links no longer work and my SEO is nearly non-existent. I’ve been attempting to find an htaccess rule that will redirect all trailing slash URLs to URLs with no trailing slash, but as of now, nothing works.
2
Answers
Use this redirect rule as your very first rule to remove trailing slash:
You don’t want to remove it 100%for SEO in WordPress.#
But this will show you how to if you want that. WordPress “/” fixes. My WordPress Gist
Can convert so it’s helpful
Config File: nginx.conf
…
…
Description WordPress “/” PHP fixes
Retrieve trailing slash string, if blog set for adding trailing slashes.
Conditionally adds a trailing slash if the permalink structure has a trailing slash, strips the trailing slash if not. The string is passed through the
‘user_trailingslashit’
filter. Will remove trailing slash from string, if blog is not set to have them.Usage
Parameters
Adds/removes a trailing slash based on the permalink structure.
codex.wordpress. /Function_Reference/user_trailingslashit
2.
If you want to add “/”
Examples
$path will now contain:
(Notice the trailing slash)
https://codex.wordpress.org/Function_Reference/trailingslashit
3.
This is new
The most important part of any test is the assertion. An assertion is a comparison between the value you expect to get from the system and the value that you actually get. The very simplest tests may consist of nothing but a single assertion. Example:
The
assertSame()
method accepts two parameters: the expected value (in this case, the hardcoded string'foo/')
, and the actual value (the value returned bytrailingslashit())
.An annotated list of common assertions can be found below.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#assertions
Try these rules:
(in www.example.com's server block) rewrite ^/$ http://example.com permanent break; rewrite ^/main(.*)$ http://example.com$1 permanent break; rewrite ^(.*)$
http://blog.example.com$1 permanent;
Make sure you reload nginx.With this config: