简体   繁体   English

重定向子域的根目录,而不是文件夹

[英]Redirect root of subdomain, not the folders

Probably a simple .htaccess RewriteRule problem but I can't figure it out. 可能是一个简单的.htaccess RewriteRule问题,但我无法弄清楚。

This is the situation: 这种情况:

  • subdomain.domain.com now has a simple HTML page subdomain.domain.com现在有了一个简单的HTML页面
  • subdomain.domain.com/folderA , subdomain.domain.com/folderB contains app logic, app data, ... subdomain.domain.com/folderAsubdomain.domain.com/folderB包含的应用程序逻辑,应用数据,...

I'm going to upgrade the simple HTML-page, but in a CMS so it can't stay on that location anymore. 我将升级简单的HTML页面,但要升级到CMS,这样它就不能再停留在该位置了。

How do I redirect all traffic going to subdomain.domain.com ( /index.htm or any other file here) to www.domain.com/somepage without rewriting requests to subdomain.domain.com/folderA etc or avoiding that requests made to any of those files end up at www.domain.com/folderA/ ... 如何将所有/index.htm subdomain.domain.com/index.htm或此处的任何其他文件)的流量重定向到www.domain.com/somepage 而无需将请求重写为subdomain.domain.com/folderA等,或避免对这些文件中的任何一个最终都位于www.domain.com/folderA/ ...

Try the following in the .htaccess file in the document root of your subdomain: 在您的子域文档根目录的.htaccess文件中尝试以下操作:

RewriteEngine On
RewriteCond ${REQUEST_FILENAME} !-d
RewriteRule ^[^/]+$ /somepage [R=302,L]

For any URL that does not contain a slash (directory separator) and is not itself a directory then redirect to /somepage . 对于任何不包含斜杠(目录分隔符)并且本身也不是目录的URL,然后将其重定向到/somepage

This does assume that you have DirectoryIndex set appropriately so that a request for the bare domain is rewritten (which is not handled by the above). 这确实假定您已正确设置DirectoryIndex以便重写对裸域的请求(上述内容未处理)。

Change the 302 (temporary) redirect to 301 (permanent) when you are sure it's working OK. 确定可以正常工作时,将302 (临时)重定向更改为301 (永久)。 (301s are cached.) (已缓存301。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM