Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache Mod Rewrite-重定向到除特定URL之外的子域(codeigniter)_Apache_Mod Rewrite_Subdomain - Fatal编程技术网

Apache Mod Rewrite-重定向到除特定URL之外的子域(codeigniter)

Apache Mod Rewrite-重定向到除特定URL之外的子域(codeigniter),apache,mod-rewrite,subdomain,Apache,Mod Rewrite,Subdomain,我正在尝试将所有流量重定向到子域 www.example.com、example.com、sub.othersite.com 全部重写到sub.othersite.com <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # ignore system folder RewriteCond %{REQUEST_URI} ^system.* RewriteCond $1 !^(client/*)

我正在尝试将所有流量重定向到子域

www.example.com、example.com、sub.othersite.com 全部重写到sub.othersite.com

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # ignore system folder
  RewriteCond %{REQUEST_URI} ^system.*
  RewriteCond $1 !^(client/*)   
  RewriteRule ^(.*)$ /index.php?/$1 [L]

  #Checks to see if the user is attempting to access a valid file,
  #such as an image or css document, if this isn't true it sends the
  #request to index.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\.php|images|robots\.txt|css)
  RewriteRule ^(.*)$ index.php?/$1 [L] 

  # if it is the SPECIAL URI redirect and EXIT
  RewriteCond $1 !^(/THE/URI)   
  RewriteCond %{HTTP_HOST} !^www.example.com$
  RewriteRule ^(.*)$ http://www.example.com/THE/URI [L]

  #catch all other traffic        
  RewriteCond %{HTTP_HOST} !^example.anothersite.com$
  RewriteRule ^(.*)$ http://example.anothersite.us/$1 


</IfModule> 
它工作得很好。现在我需要排除重定向到子域的单个URL

因此,如果www.example.com/THE/URI出现,我希望mod rewrite忽略子域重写并将其发送到主域

看起来很简单,但我不能让它工作,因为我有一个额外的重写,以确保所有的域(也有一对夫妇停泊)漏斗到一个单一的域交付内容

我还有其他一些重写条件。它们都列在这里。如果有人能给我指出正确的方向-我需要基本上做到这一点:

如果传入请求是针对/THE/URI的 然后访问www.example.com/THE/URI 否则 重写到sub.othersite.com

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # ignore system folder
  RewriteCond %{REQUEST_URI} ^system.*
  RewriteCond $1 !^(client/*)   
  RewriteRule ^(.*)$ /index.php?/$1 [L]

  #Checks to see if the user is attempting to access a valid file,
  #such as an image or css document, if this isn't true it sends the
  #request to index.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\.php|images|robots\.txt|css)
  RewriteRule ^(.*)$ index.php?/$1 [L] 

  # if it is the SPECIAL URI redirect and EXIT
  RewriteCond $1 !^(/THE/URI)   
  RewriteCond %{HTTP_HOST} !^www.example.com$
  RewriteRule ^(.*)$ http://www.example.com/THE/URI [L]

  #catch all other traffic        
  RewriteCond %{HTTP_HOST} !^example.anothersite.com$
  RewriteRule ^(.*)$ http://example.anothersite.us/$1 


</IfModule> 

重新启动发动机
重写基/
#忽略系统文件夹
重写COND%{REQUEST_URI}^系统*
1美元^(客户/*)
重写规则^(.*)$/index.php?/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
1美元^(索引\.php | images | robots\.txt | css)
重写规则^(.*)$index.php?/$1[L]
#如果是特殊URI,则重定向并退出
1美元^(/THE/URI)
重写cond%{HTTP_HOST}^www.example.com$
重写规则^(.*)$http://www.example.com/THE/URI [L]
#赶上所有其他交通工具
重写cond%{HTTP_HOST}^example.anothersite.com$
重写规则^(.*)$http://example.anothersite.us/$1 
已解决。 答案很简单。我只需要从最终重写中排除URI和查询字符串,因为重写的上半部分在URL后面附加了一个查询字符串

为了让我的应用程序工作,我仍然需要进行初始重写(获取任何URI并在内部将其映射到index.php?URI)

最终代码:

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        #Removes access to the system folder by users.
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteCond $1 !^(client/*)   
        RewriteRule ^(.*)$ /index.php?/$1 [L]

                # our URL is prepped now - query string appended, so let's redirect it
                # ONLY if it's not the ONE URL we need to keep

        RewriteCond %{REQUEST_URI} !^/THE/URI   
        RewriteCond %{QUERY_STRING} !^/THE/URI
        RewriteCond %{HTTP_HOST} !^sub.example.com$
        RewriteRule ^(.*)$ http://sub.example.com/$1  [R=302]
</IfModule>

重新启动发动机
重写基/
#删除用户对系统文件夹的访问权限。
重写COND%{REQUEST_URI}^系统*
1美元^(客户/*)
重写规则^(.*)$/index.php?/$1[L]
#我们的URL现在已经准备好了-附加了查询字符串,所以让我们重定向它
#除非它不是我们需要保留的URL
重写cond%{REQUEST_URI}^//URI
重写cond%{QUERY_STRING}^//URI
重写cond%{HTTP_HOST}^sub.example.com$
重写规则^(.*)$http://sub.example.com/$1[R=302]
已解决。 答案很简单。我只需要从最终重写中排除URI和查询字符串,因为重写的上半部分在URL后面附加了一个查询字符串

为了让我的应用程序工作,我仍然需要进行初始重写(获取任何URI并在内部将其映射到index.php?URI)

最终代码:

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        #Removes access to the system folder by users.
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteCond $1 !^(client/*)   
        RewriteRule ^(.*)$ /index.php?/$1 [L]

                # our URL is prepped now - query string appended, so let's redirect it
                # ONLY if it's not the ONE URL we need to keep

        RewriteCond %{REQUEST_URI} !^/THE/URI   
        RewriteCond %{QUERY_STRING} !^/THE/URI
        RewriteCond %{HTTP_HOST} !^sub.example.com$
        RewriteRule ^(.*)$ http://sub.example.com/$1  [R=302]
</IfModule>

重新启动发动机
重写基/
#删除用户对系统文件夹的访问权限。
重写COND%{REQUEST_URI}^系统*
1美元^(客户/*)
重写规则^(.*)$/index.php?/$1[L]
#我们的URL现在已经准备好了-附加了查询字符串,所以让我们重定向它
#除非它不是我们需要保留的URL
重写cond%{REQUEST_URI}^//URI
重写cond%{QUERY_STRING}^//URI
重写cond%{HTTP_HOST}^sub.example.com$
重写规则^(.*)$http://sub.example.com/$1[R=302]