将 301 重定向添加到 Codeigniter .htaccess

Jee*_*usu 0 .htaccess mod-rewrite redirect codeigniter

我一直在尝试为最近移动的页面设置重定向。该页面最初位于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/
Run Code Online (Sandbox Code Playgroud)

Jee*_*usu 5

在文件解决问题后RewriteRrule的顶部添加一个。.htaccessRewriteBase /

RewriteRule ^foo/$ /foo/bar [R=301,L]