0

我目前正在迁移域 [old_domain] -> [new_domain]。

当我来到 /etc/httpd/conf/httpd.conf 中的 htaccess 规则和配置文件时,问题就出现了:

httpd.conf

AllowOverride All

最初我找不到将上述内容放在哪里以允许 .htaccess 重写规则起作用,我仍然担心我可能错误地允许所有人使用它。

我试过把它放在类似但没有效果的东西中:

<Directory "/path/to/django/project/">
    AllowOverride All
</Directory>

一旦我确实让 .htaccess 文件重写工作(使用以下内容),URL 开始返回一些奇怪的东西。

.htaccess 在 django 项目目录中

RewriteEngine On
RewriteCond %{HTTP_HOST} !^old_domain.com/$ [NC]
RewriteRule ^(.*)$ http://new_domain.com/$1 [L,R=301]

已发送网址

http://old_domain.com/news/

收到网址

http://new_domain.com/apache/production.wsgi/news/

快到了……但有人能说明为什么会发生这种情况吗?我真的不想在 new_domain 端剥离 /apache/production.wsgi/ (除非这是预期的?)

提前致谢。

编辑:一个快速修复包括使用 django 的 HttpResponsePermanentRedirect。这是不好的做法吗?

4

1 回答 1

2

如果要在 django 文件夹中使用 rewrite 指令,则需要启用覆盖。否则它们将被忽略:

http://httpd.apache.org/docs/current/mod/core.html#allowoverride

希望这对重写有诀窍:

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} !^newdomain\.com 
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

请务必在 RewriteCond 的域中划定句点。在正则表达式中, . 意思是“匹配所有”

于 2013-05-01T22:01:29.377 回答