2014-09-03 117 views
0

令人惊讶的是,我无法找到任何答案(以简单的方式)。htaccess - 301将特定文件和扩展名重定向到文件夹根

我在找一个站点上的一些旧网址重定向到新的结构。问题是 - 凭我的能力,我遇到了问题。

我想什么:

重定向到/oldfolder/example.htmlhttp://website.com/newfolder/

所以我用这个:

Redirect 301 /oldfolder/example.html http://website.com/newfolder/ 

问题是,这似乎结束了重定向到: http://website.com/newfolder/example.html

而我似乎无法阻止它追加旧的文件名新URL的结尾处为。

我也试过:

RedirectMatch 301 ^/oldfolder/example.html$ http://website.com/newfolder/$ 

但仍没有运气。

任何人都可以帮助我正确的语法从文件重定向到不同的文件夹根目录吗?

编辑: 由于在第一个答案解决以下似乎并没有帮助,我感觉有更多的它,所以这里是一些更多的信息.​​..

这里是我的.htaccess文件:

Options +FollowSymLinks 
RewriteEngine On 

# WORKING 
Redirect 301 /defaultsite http://improvemyrunning.com/ 
Redirect 301 /book/index.html http://improvemyrunning.com/ 
Redirect 301 /contact/index.html http://improvemyrunning.com/contact/ 
Redirect 301 /camps/ http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/ http://improvemyrunning.com/ 
Redirect 301 /assets/neil_feedback.pdf http://improvemyrunning.com/run-camps/ 
Redirect 301 /team/index.html http://improvemyrunning.com/about/ 
Redirect 301 /coaching/index.html http://improvemyrunning.com/services/ 


# BROKEN 
Redirect 301 /camps/feedback.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /camps/itinerary.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/index.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/index2.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/1.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/2.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/3.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/4.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/5.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/6.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/7.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/8.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/9.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/10.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/11.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/12.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/13.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/14.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/15.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/16.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Glenholm%20Countryside/slides/17.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Run%20Training%20Camp%20September%202013/index.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Run%20Training%20Camp%20September%202013/slides/Glenholm_Centre.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Run%20Training%20Camp%20September%202013/slides/Group_Picture.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Run%20Training%20Camp%20September%202013/slides/Beautiful_Weather.html http://improvemyrunning.com/run-camps/ 
Redirect 301 /photos/Run%20Training%20Camp%20September%202013/slides/Sunday_Trail_Running.html http://improvemyrunning.com/run-camps/ 


# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 

有人可以看到我失踪的任何东西吗?也许在底部的WordPress的htaccess规则是干涉?

回答

0

您可以使用此规则:

RedirectMatch 301 ^/oldfolder/example\.html$ /newfolder/ 

确保测试它在新的浏览器,以避免旧的301浏览器缓存。

如果您正在使用mod_rewrite那么你就可以在你的根的.htaccess使用:

RewriteEngine On 

RewriteRule ^oldfolder/example\.html$ /newfolder/ [L,NC,R=301] 
+0

非常感谢,我相信一定会有更多的我的问题,因为这两种解决方案都在工作。我将详细说明我的最初问题。 – alexcowles 2014-09-03 12:59:20

+0

我已经添加了我的htaccess文件 - 有人告诉说,也许Wordpress规则正在干涉... – alexcowles 2014-09-03 13:03:29

+0

哪个URL没有重定向。我建议只使用'mod_rewrite'规则,所以不要使用'Redirect'规则。 – anubhava 2014-09-03 13:06:09