[英]Laravel 4.1 Redirect all requests from www.mydomain.com to mydomain.com with 301 permanent redirect
[英]Redirect from www.mydomain.com/foo to www.mydomain.com/foo/
我在.htaccess文件中有一段代碼:用結尾的斜杠替換php擴展名。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} (.*)/$
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule (.*)/$ $1.html [L]
RewriteCond %{REQUEST_URI} (.*)/$
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule (.*)/$ $1.php [L]
RewriteCond %{REQUEST_URI} (.*)/$
RewriteCond %{REQUEST_FILENAME}\.cgi -f
RewriteRule (.*)/$ $1.cgi [L]
## redirect /dir/foo to /dir/foo/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f [OR]
RewriteCond %{REQUEST_FILENAME}\.php -f [OR]
RewriteCond %{REQUEST_FILENAME}\.cgi -f
RewriteRule .* %{REQUEST_FILENAME}/ [R=301,L]
</IfModule>
我的問題是如何將所有請求從www.mydomain.com/foo
重定向到www.mydomain.com/foo/
? (注意尾隨斜杠)
解:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
來源和說明: http : //enarion.net/web/htaccess/trailing-slash/
RewriteCond %{REQUEST_FILENAME} !-f
如果文件存在,則不重定向 RewriteCond %{REQUEST_URI} !(.*)/$
條件:“如果沒有斜杠” RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]
重定向到URL +斜杠
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.