我一直在尝试为最近移动的页面设置重定向。该页面最初位于http://example.com/foo/
,但后来移至http://example.com/foo/bar/
。
我在我的站点.htaccess
文件中尝试了以下规则:
RedirectMatch 301 ^/foo/$ /foo/bar/
但是,转到 url 会http://example.com/foo/
导致重定向到 url http://example.com/foo/bar/?/foo/
。虽然 url 有效并且我想重定向到加载的页面,但我很想摆脱?/foo/
url 末尾的额外内容。
这是我的完整 .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/