如何使用mod_rewrite命令将子域名重写为包含子域名的路径



使用mod_rewrite,如何重定向:

http://subdomain.noorderlijn.be/files/file.jpg

:

http://www.noorderlijn.be/files/subdomain/file.jpg

尝试将此添加到subdomain的web文档根文件夹(通常为public_htmlhtdocs)中的.htaccess文件:

RewriteEngine On
RewriteCond %{HTTP_HOST} subdomain.noorderlijn.be
RewriteRule ^files/(.*) http://www.noorderlijn.be/files/subdomain/$1 [NE,R,L]

一旦您对重定向工作感到满意,您可以将R更改为R=301以使其永久存在。这假设mod_rewrite是安装为htaccess文件激活。如果您不确定,要检查是否安装了mod_rewrite,请查看phpinfo();输出中的已安装模块列表默认情况下,htaccess文件不启用mod_rewrite。如果您正在管理自己的服务器,请打开httpd.conf并确保webroot目录块包含以下一行:AllowOverride FileInfoAllowOverride All

最新更新