我正在使用 apache2 和 laravel 所以我把這段代碼.htaccess放在/public檔案夾里
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/?(blog|dont/you|brave-to|fvck|me)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
上面的代碼僅在 url 特定于/url
一個例子https://mywebsite.com/blog或https://mywebsite.com/dont/you
因此,這RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
將重定向您以獲取tailling slash
也會如此https://mywebsite.com/blog/

但是當我想添加動態 slug 這個不作業的


正如您所看到的,當我嘗試blog使用隨機文本更改此規則強制添加時/
我只需要為特定的 url 和特定的 url 強制添加尾斜線
uj5u.com熱心網友回復:
好的所以我得到它使用這個條件
RewriteEngine On
// check if not a file
RewriteCond %{REQUEST_FILENAME} !-f
// check if there start with blog/ and not end with /
RewriteCond %{REQUEST_URI} ^/(blog/.*)[^/]$ [OR]
// OR check if contain specific words
RewriteCond %{REQUEST_URI} ^/(blog|dont/you|brave-to|fvck|me)$
// the do the rule
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
這是一個
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/488484.html
下一篇:Python不會關閉最后一個檔案
