.htaccess redirect ~ [fake-subdomain.domain.com/*] to [domain.com/*]

梦想的初衷 提交于 2019-12-11 09:26:49

问题


I have been searching for this for many hours and I have no idea how to accomplish that. I need to make the following 301 permanent redirect:

When people visit http://web.domain.com.br/something/

They should be redirected to http://domain.com.br/something/

Where (important!), the /something/ is not a real directory, it is a sub-blog from the wordpress multisite installation. There are another rules on the root .htaccess file already in action. They are:


    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]

    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]

My domain actually already has a some kind of redirect, out of my sight, created by someone on the control panel. They did create the following:

When you visit: http://web.domain.com.br/

You go to: http://domain.com.br/

For the home part, this is ok. But whenever I try something like: http://web.domain.com.br/opaopa/

I got redirected to: http://domain.com.br/

AND, if I phisically create inside my root the directory /opaopa/ the redirect trhows me there... However, I can't create real directories for my wordpress subsites, because the apache gives preference to them, instead of loading the "magic" of the wordpress multisite network.

Sorry if it sounds confusing... English is not my natural language.

Thanks sooo much for your attention. Regards, G.


回答1:


RewriteCond %{HTTP_HOST} !^domain\.com\.br$ [NC]
RewriteRule (.*) http://domain.com.br/$1 [L,R=301]

add this just after RewriteBase ... (so before all the other rewrite-rules)



来源:https://stackoverflow.com/questions/11353139/htaccess-redirect-fake-subdomain-domain-com-to-domain-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!