如何从网址中删除尾部斜杠

时间:2017-01-18 07:20:53

标签: .htaccess url url-redirection

我遇到了URL末尾的斜杠的问题。我在线检查URL重定向,结果显示我的页面上有太多的重定向,所以我需要减少重定向,因为我的链接有以下结果

https://example.com/xyz/pqr
302 Found
https://example.com/xyz/pqr/
302 Found
https://example.com/xyz/pqr//
302 Found
https://example.com/xyz/pqr///
302 Found
https://example.com/xyz/pqr////
302 Found
https://example.com/xyz/pqr/////
302 Found
https://example.com/xyz/pqr//////
302 Found
https://example.com/xyz/pqr///////
302 Found
https://example.com/xyz/pqr////////
302 Found
https://example.com/xyz/pqr/////////
302 Found
https://example.com/xyz/pqr//////////
302 Found
https://example.com/xyz/pqr///////////
302 Found
https://example.com/xyz/pqr////////////
302 Found
https://example.com/xyz/pqr/////////////
302 Found
https://example.com/xyz/pqr//////////////
302 Found
https://example.com/xyz/pqr///////////////
302 Found
https://example.com/xyz/pqr////////////////
302 Found
https://example.com/xyz/pqr/////////////////
302 Found
https://example.com/xyz/pqr//////////////////
302 Found
https://example.com/xyz/pqr///////////////////
302 Found

我该如何解决这个问题?我不知道我哪里错了.. !!任何帮助都是有意义的。提前谢谢。

这是我的htaccess代码:

RewriteEngine on
RewriteCond %{QUERY_STRING} p=3842
RewriteRule ^ /? [R=301,L]

这就是我在htaccess代码中拥有的全部内容,其余只是301重定向,仅此而已...... !!

1 个答案:

答案 0 :(得分:0)

要使用.htaccess删除尾部斜杠,您可以使用:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]