https://preview.redd.it/1hwz6ncr792d1.png?width=1074&format=png&auto=webp&s=f512d1125c387d8ecca2de9bc0e6c0f74d96b7a0
I have a blog at [https://www.gizmogo.com/blog/](https://www.gizmogo.com/blog/) and
I want to remove the trailing slash from the address so it appears as [https://www.gizmogo.com/blog](https://www.gizmogo.com/blog).
I’ve tried adjusting the **Permalink** settings and using **PHP functions**, but haven’t been successful.
i could not do it even in Permalink Manager plugin. 🙁
I don’t have .htaccess file to used this kind of code :
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R]
I have tried this in function php file :
`add_action(‘init’, function() {`
`$uri = $_SERVER[‘REQUEST_URI’];`
`// Check if URI is not the homepage and ends with a slash`
`if ($uri != ‘/’ && substr($uri, -1) == ‘/’) {`
`// Properly trim the slash and perform a 301 redirect`
`wp_redirect(rtrim($uri, ‘/’), 301);`
`exit();`
`}`
`});`
Can someone help me solve this canonical issue with the URLs?
[ad_2]
Not to be That Person, but is there a reason you need to remove the trailing slash?
It’s not possible to do what you want in the Apache/ nginx / cgi-bin web server world that WordPress lives in. That’s because the file you’re serving is actually https://example.com/blog/index.php . The way Apache and/ or nginx work, you’re serving the designated default file (index.php) from the …/blog/ subdirectory on the server file system.
Other web servers ( node.js for example ) have “routes” ( /blog/ for example ) that aren’t so closely tied to mapping a local file system to the structure of the URLs.
Remove it in your permalink settings. If you remove it from the end of your custom structure it’ll remove it everywhere. I discovered this by accident a few months ago.