-1

I've tried several ways to remove the trailing slash from my URL in .htaccess and nothing worked but now even my URL can't be found because now it has a slash.

Here is what my .htaccess looks like. I need to get rid of so many redirects and don't have a clue how to do it. And I would like to remove the slash on my permalink on my WordPress site because it's not good SEO and now I can't even make mine work.

How do I get rid of stuff here that isn't working and get rid of slash on my URL example.com? It doesn't matter for rest because I've done a lot of work and there are a lot of trailing slashes on my site. Just want my Domain Permalink Slash gone.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)/+$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)/+$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

# BEGIN LSCACHE
# END LSCACHE
# BEGIN NON_LSCACHE
# END NON_LSCACHE

# BEGIN GD-SSL
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^electricridespro\.com$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Header add Strict-Transport-Security "max-age=300"
</IfModule>
# END GD-SSL


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)/+$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)/+$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)/+$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Of course I don't want my GD-SSL file gone but need to get the rest out of here safely and get exact code to make my Permalink example.com/ get rid of slash and make it example.com but not take the slashes off the rest that are on other URLs in my site so my site does't get broken.

  • 1
    Why do you have so many duplicate WordPress sections in your .htaccess? Only one of them is needed. The others are not even going to be used. – Stephen Ostermiller Oct 29 '18 at 23:25
  • "but not take the slashes off the rest" - The code you posted looks like it is already doing this? Is this in error? – MrWhite Oct 30 '18 at 0:17
  • My url is electricridespro.com and now my permalink in Wordpress is https:///electricridespro.com/ and when I do site audit it shows both with / after and they don't recognize my correct url. Can i get rid of any stuff? Can you give me correct code to place and tell me where at top or bottom? i only want to take the slash off my domain url because i have a lot of urls with slashes and how do i do that? MrWhite – Robert Gaskill Oct 30 '18 at 0:34
  • Of course I don't want my GD-SSL file gone but need to get the rest out of here safely and get exact code to make my Permalink electricridespro.com/ get rid of slash and make it electricridespro.com but not take the slashes off the rest that are on other urls in my site so my site does't get broken. Can you give me exact code and tell me where to place it? can i delete some of them? MrWhite – Robert Gaskill Oct 30 '18 at 0:36
  • 1
    But, as @Stephen has already pointed out in his answer, a slash at the end of the domain name is correct! "they don't recognize my correct url." - Who is "they"? (You have three slashes after the protocol in you comment - but I assume that is just a typo?) – MrWhite Oct 30 '18 at 0:43
3

You cannot remove the trailing slash from the domain name URL. Your home page may or may not have a slash at the end of the domain name depending on which browser you use. Most browsers show the slash. As a webmaster, you cannot control the trailing slash on the home page. It is always implicitly there. There is no .htaccess rule you can use to get rid of it. See:

You say "now even my url can't be found because now it has a slash". The trailing slash on your home page URL is not the issue. I'm not sure if mean that there is a "404 not found" error, or if you mean that search engines are not indexing the page. If it is the former, it will work the same with or without the slash for the home page URL. If it is the latter, search engines will index pages both with slashes and without.

You also say "I would like to remove the slash on my permalink on my Wordpress site because it's not good SEO". There is no meaningful difference in SEO between URLs that have and do not a trailing slash. Historically it has been used on URLs that represent a directory. Many times I've seen recommendations to omit trailing slashes for URL simplicity. However, having trailing slashes on your URLs won't hurt SEO as long as you link to that version of them consistently. And as I've said earlier, there is no way to remove a slash on the home page.

  • if you do a check canonical website check it doesn't recognize https://electricridespro.com without slash and it is showing canonical as https://electricridespro.com/ even if I put a meta tag in head section or my Yoast plugin. it puts wrong url @Stephen Ostermiller – Robert Gaskill Oct 30 '18 at 0:46
  • Can I remove duplicate stuff in htaccess? so my site doesnt have so many redirects. Is there a code out there that takes out slash on url that you can provide me and do I add it up top or bottom? @Stephen Ostermiller – Robert Gaskill Oct 30 '18 at 0:48
  • 2
    For the home page, the canonical version would ideally have the slash. The two URLs are completely equivalent. There is no way to redirect from one to the other. It doesn't matter if the home page URL is recognized with or without the slash. It just doesn't matter. – Stephen Ostermiller Oct 30 '18 at 2:06
  • 1
    You can usually remove duplicate sections in .htaccess. I would certainly try to do so if I were you. As I have tried to say many times here, there is no code for .htaccess that can possibly add or remove a slash on your home page URL. – Stephen Ostermiller Oct 30 '18 at 2:07
  • 1
    "Historically it has been used on URLs that represent a directory." History means nothing. It's the written standard. – Rob Oct 30 '18 at 14:19

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.