fbpx Remove slash from the end of URL - Meysmahdavi

Remove slash from the end of URL

Remove / from the end of WordPress links using .htaccess file

In this WordPress tutorial, we want to provide you with a simple and short, but practical way to remove slash (/) from all links on your site.

Of course, all sites are so expanded that all of them may have links with an / at the end. But today we will show you how you can get rid of them all using a short code snippet.

Be extremely careful when using this code. In some content management systems (cms) such as WordPress, especially after installing SEO plugins, the slash / sign is always at the bottom of the site pages link and it is not necessary to delete it, but it is better to do so.

Therefore, by redirecting the address with slash to the address without slash, we prevent such problems. To do this, just copy the following code into the .htaccess file in WordPress.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpg|png|jpeg|css|js)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]

In the above code, the formats gif | jpg | png | jpeg | css | js are excluded from removing the slash from the bottom of the link. You can add more formats if needed.

  • Share This Story

about author



Leave a Reply

Your email address will not be published. Required fields are marked *