我一直在嘗試爲最近移動的頁面設置重定向。該網頁最初是在http://example.com/foo/
,但後來轉移到http://example.com/foo/bar/
。添加301重定向到Codeigniter .htaccess
我嘗試以下規則在我的網站.htaccess
文件:
RedirectMatch 301 ^/foo/$ /foo/bar/
但是要到URL http://example.com/foo/
導致重定向到URL http://example.com/foo/bar/?/foo/
。雖然網址的作品和我想重定向到加載頁面,我很想擺脫在URL的末尾多餘的?/foo/
。
這裏是我的全部的.htaccess:
RewriteEngine On
RewriteBase/
# add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [R=301,L]
# allow access to certain directories in webroot
RewriteCond $1 !^(index\.php|robots\.txt|css/|lib/|js/|images/|^(.*)/images)
# gets rid of index.php
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# page redirects
RedirectMatch 301 ^/foo/$ /foo/bar/
這會的工作,但我覺得這個可能應該在'.htaccess'或Apache設置的現場進行,因爲這將是其他開發人員的第一位看他們是否必須在您的網站上工作。把它放在控制器中並不是我想要找到這種邏輯的地方。 – Jeemusu