Windows Server 2008上的htaccess重写规则& Apache不工作

时间:2013-07-09 16:50:31

标签: apache .htaccess url-rewriting

我正在用重写规则拉出我的头发我试图实施几天,因为我已经完全重新建立了一个网站,其中OLD URL现在必须重定向到新URL

(注:在Windows 2008R2上运行Apache)

OLD链接始终是:
www.domain.com/files /

新链接是: domain.com/_fileuploads /

示例(OLD)URL www.domain.com/files/Media/Statistics/Germany/services%202003-2012.pdf

我几乎尝试了一切:

Redirect 301 /files/Media/Statistics/Germany/services%202003-2012.pdf$  http://domain.com/_fileuploads/entries/Statistics/services%202003-2012.pdf

RewriteRule ^/files/Media/Statistics/Germany/services%202003-2012\.pdf$ http://domain.com/_fileuploads/entries/Statistics/services%202003-2012.pdf [NC,R=301,L]

RedirectMatch 301 /files/Media/Statistics/Germany/services%202003-2012.pdf$ http://domain.com/_fileuploads/entries/Statistics/services%202003-2012.pdf

以上解决方案均不适合我,我总是找不到404 非常感谢您明智的投入。

2 个答案:

答案 0 :(得分:0)

最好只为此目的使用mod_rewrite并避免使用mod_alias。

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^files/Media/(.+)$ /_fileuploads/entries/$1 [L,NC,R=301]

答案 1 :(得分:0)

问题是,当从浏览器栏复制URL时,白色空格用%20填充到文本编辑器。

这个解决方案实际上对我有用,其中%20被替换为[\ |%2520]:

RewriteRule 
^/files/Media/Statistics/Germany/services[\ |%2520]2003-2012\.pdf
"http://domain.com/_fileuploads/entries/Statistics/services 2003-2012.pdf"