3

I have a website with a separate blog in a /wordpress/ directory. Currently the blog is available at https://website.com/wordpress/ The blog items do not have a trailing slash and are available at https://website.com/wordpress/newsitem-name

I would like to have the blog available at https://website.com/wordpress (without the trailing slash) and have the trailing slash version (/wordpress/) redirect to the non trailing slash (/wordpress).

I played around with 'DirectorySlash Off', but all I got were incorrect redirects, or infinite redirects. Both broke my site. What do I need to change in my .htacces files?

My website file structure is as follows:


    .htaccess (#1) 
    index.php
    otherscript.php
    /wordpress
        .htaccess (#2)
        index.php
        other-regular-wordpress-files

.htaccess #1 contains the following:


    Options -Indexes
    RewriteEngine On
    RewriteBase /

    #Remove trailing slash
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} (.*)$
    RewriteRule ^(.*)/$ https://%{HTTP_HOST}/$1 [R=301,L]

.htaccess #2 contains the following:


    Options -Indexes
    # BEGIN WordPress
    
    RewriteEngine On
    RewriteBase /wordpress
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    
    # END WordPress

What changes do I need to make to be able to visit my blog at "/wordpress"? Thank you very much in advance.

Ruud Kok
  • 101
  • 9
  • Is there actual benefit to you to remove the slash besides aesthetics? Visitors don't memorize (or care) whether or not URLs have trailing slashes as long as they can visit the page. – Justin R. Jun 12 '18 at 15:55
  • 1
    @Justin: Yes there is. WordPress links to the version without trailing slash in the breadcrumbs (by Yoast SEO). This creates unneeded 301-redirects, which in turn result in search engines wasting crawling budget on URL's that have no need to exist. – Ruud Kok Jun 14 '18 at 07:48
  • Fair enough. I think the answer you're looking for is the one posted by Gras Double (should be 2nd answer) on https://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url – Justin R. Jun 14 '18 at 15:36
  • Hello, did you solve it? – Nico Real Sep 28 '21 at 13:16

0 Answers0