使用mod_rewrite, 如何将我重定向:
http://subdomain.noorderlijn.be/files/file.jpg
到
http://www.noorderlijn.be/files/subdomain/file.jpg
解决方案
尝试添加这样的的.htaccess
文件中的Web文档根目录文件夹(通常的public_html
或的htdocs
的子域:
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} subdomain.noorderlijn.be
重写规则^文件/(.*)http://www.noorderlijn.be/files/subdomain/$1 [NE,R,L]
一旦你感到满意的是重定向的工作原理,你可以修改研究
到 R = 301
,使它常驻。
这是假设的mod_rewrite是两个安装和 htaccess的文件被激活。
如果你不能确定,要检查是否安装了mod_rewrite,看看已安装的模块列表中 phpinfo()函数的输出;
默认情况下,不启用mod_rewrite并htaccess的文件。如果您在管理自己的服务器上,打开的httpd.conf
并确保Web根目录目录块包含下列行之一:的AllowOverride FileInfo的
或的AllowOverride全部
Using mod_rewrite, How would I redirect:
http://subdomain.noorderlijn.be/files/file.jpg
to:
http://www.noorderlijn.be/files/subdomain/file.jpg
解决方案
Try adding this to the .htaccess
file in the web document root folder (often public_html
or htdocs
) of subdomain
:
RewriteEngine On
RewriteCond %{HTTP_HOST} subdomain.noorderlijn.be
RewriteRule ^files/(.*) http://www.noorderlijn.be/files/subdomain/$1 [NE,R,L]
Once you are satisfied that the redirect works, you can change the R
to R=301
to make it permanent.
This assumes that mod_rewrite is both installed and activated for htaccess files.
If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo();
By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf
and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo
or AllowOverride All