我有多个网站托管在GoDaddy上。我有一个网站在根文件夹(/)和其他网站的不同文件夹下的根。
www.mydomain.com at /www.something.com /something如果用户键入网址www.mydomain.com/something,它将显示网站www.something.com的内容。
如果他/她在www.mydomain.com之后键入任何子目录名,我希望用户被重定向到www.mydomain.com。
根文件夹中的.htaccess文件中有以下内容:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]发布于 2017-01-02 19:41:24
这将将子目录中的任何内容重定向到根目录中,以便在根.htaccess文件中使用。
# Redirect anything in a sub-directory to root
# (any URL with a slash in it, not including the first one)
RewriteRule / / [R=301,L]记住,所有的样式表、图像、javascript等等都不能放在子目录中,因为它们不能工作(它们也会被重定向到root )。网站的一切都必须以这种方式扎根。
发布于 2017-01-02 19:43:50
您可以在站点根.htaccess中使用此规则:
RewriteEngine On
# redirect to / of something or somethingelse is accessed from mydomain.com
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^(something|somethingelse)/ / [L,R=301,NC]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]https://stackoverflow.com/questions/41432416
复制相似问题