簡體   English   中英

301重定向以擺脫斜線

[英]301 redirect to get rid of the slash

在htaccess中是否有辦法將所有頁面重定向到/沒有任何內容。 所以例如我想要這個

http://somesite.com/something/ ==> http://somesite.com/something
http://somesite.com/another_thing/ ==> http://somesite.com/another_thing
http://somesite.com/page3/ ==> http://somesite.com/page3
http://somesite.com/page4/ ==> http://somesite.com/page4

page3,page4,something,another_thing都是每個目錄中都有一個index.php文件......這就是我處理它的方式

在我的htaccess中,我正在擺脫/由此

DirectorySlash Off
RewriteCond %{REQUEST_FILENAME}/index\.php -f 
RewriteRule ^(.+)$ /$1/index.php [NC,QSA,L]

我基本上只是因為seo原因而想要301重定向,所以即使它們被緩存,每個人都會在非斜杠頁面上結束。提前知道。

這個

如果要從包含它們的所有請求中刪除尾部斜杠,請嘗試:

RewriteRule   ^/(.+)/$  /$1   [R]

請參閱URL重寫指南並查找Canonical URL 此外,請注意DirectorySlash Off指令的文檔和安全警告。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM