-1 3 Votes

HTACCESS: Crop Trailing Slash from the end of a URL

Tip by Stefan Trost | 16/04/2013 at 03:54

Today, I would like to show you, what you can write into your .htaccess to remove the trailing slash from the end of a requested URL and to redirect the request to the address without slash automatically.

Simply write the following line to your .htaccess:

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

With this, all requests of the form:

https://www.askingbox.com/
https://www.askingbox.com/new/question/

Will be redirected to:

https://www.askingbox.com
https://www.askingbox.com/new/question

When redirecting, we automatically send the status code 301 (Moved Permanently). This shows search engines, for example, that only the new URL should be in force.

ReplyPositiveNegative

About the Author

Avatar AuthorYou can find Software by Stefan Trost on sttmedia.com. Do you need an individual software solution according to your needs? - sttmedia.com/contact
Show Profile | Message

 

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own articles on askingbox.com. How to do.