【问题标题】:htaccess port forwarding URLshtaccess 端口转发 URL
【发布时间】:2012-12-11 15:42:31
【问题描述】:

我希望设置 2 次 .htaccess 重写,但不确定它们的实际外观:

http://www.mysite.com -> http://www.myothersite.com:880

和

https://www.mysite.com -> https://www.myothersite.com:4443

只是为了处理端口转发问题...

这是我目前正在尝试的:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^cloud\.mysite\.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ http://mysite.no-ip.org:880%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^cloud\.mysite\.com$ [NC]
RewriteCond %{HTTPS} on
RewriteRule ^ https://mysite.no-ip.org:4443%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteRule ^/?$ "http\:\/\/www\.mysite\.com\/joomla" [R=301,L]

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite portforwarding


    【解决方案1】:

    通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccess的DOCUMENT_ROOT目录下:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
    RewriteCond %{HTTPS} off
    RewriteRule ^ http://www.myothersite.com:880%{REQUEST_URI} [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
    RewriteCond %{HTTPS} on
    RewriteRule ^ https://www.myothersite.com:4443%{REQUEST_URI} [R=301,L]
    

    【讨论】:

    • 谢谢。我会试一试。假设我想让它只适用于 cloud.mysite.com,那么上面唯一会改变的是 "www" -> "cloud" 吗?对我网站的所有其他 www 访问不会受到影响?
    • 是的,只需将RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC] 替换为RewriteCond %{HTTP_HOST} ^cloud\.mysite\.com$ [NC]
    • 确保 mod_rewrite 和 .htaccess 已启用。如果是,请在您的问题中发布您最新的 .htaccess,并提供一些详细信息,例如哪些 URL 不起作用。
    • 感谢您的 .htaccess 但以上规则的哪些 URL 不起作用?
    • 两个云 URL 都不起作用。 URL 没有被重写。他们只是保持不变......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 2013-02-11
    • 2012-01-12
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多