我正在尝试在Apache(httpd.conf)中设置重定向,要求很简单,只要有权访问我的域,就应该将这些访问重定向到不同的URL。我在设置服务器时编写了此代码,并仅处理了一个域。当只有一个域并正确地重定向到目的地时,该代码有效。
我添加了一个域并尝试执行相同的重定向。不幸的是,在添加第二个域重定向代码后,重定向似乎无法正常工作。
要求:
重定向' chk'下的所有文件和' enq'目录到它的移动域
初始重写规则
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteRule ^/chk/q/(.*) https://st-iex.o-p.com/lnk000/=https://st-ex.o-p.com/chk/q/$1 [L]
RewriteRule ^/enq/q/(.*) https://st-iex.o-p.com/lnk000/=https://st-ex.o-p.com/enq/q/$1 [L]
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 3
如果我只使用域名st-iex.o-p.com,则上述代码有效。
我更新了代码句柄第二个域重定向
版本2
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteCond %{HTTP_HOST} ^st-iex\.o-p\.com$ [NC]
RewriteRule ^/chk/q/(.*) https://st-iex.o-p.com/lnk000/=https://st-ex.o-p.com/chk/q/$1 [L]
RewriteRule ^/enq/q/(.*) https://st-iex.o-p.com/lnk000/=https://st-ex.o-p.com/enq/q/$1 [L]
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 3
RewriteEngine On
RewriteCond %{HTTP_HOST} ^st-iex-t\.o-p\.com$ [NC]
RewriteRule ^/chk/q/(.*) https://st-iex-t.o-p.com/lnk000/=https://st-ex.o-p.com/chk/q/$1 [L]
RewriteRule ^/enq/q/(.*) https://st-iex-t.o-p.com/lnk000/=https://st-ex.o-p.com/enq/q/$1 [L]
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 3
代码更新后,它没有工作,也没有重定向。 任何人都可以帮我解决这个重定向问题吗?
答案 0 :(得分:0)
我已经更新了RewriteRule,如下所示,现在问题已解决。 谢谢。
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteCond %{HTTP_HOST} st-iex\.o-p\.com$ [NC]
RewriteRule ^/chk/q/(.*) https://st-iex.o-p.com/lnk000/=https://st-ex.o-p.com/chk/q/$1 [L, R=301]
RewriteCond %{HTTP_HOST} st-iex\.o-p\.com$ [NC]
RewriteRule ^/enq/q/(.*) https://st-iex.o-p.com/lnk000/=https://st-ex.o-p.com/enq/q/$1 [L, R=301]
RewriteCond %{HTTP_HOST} st-iex-t\.o-p\.com$ [NC]
RewriteRule ^/chk/q/(.*) https://st-iex-t.o-p.com/lnk000/=https://st-ex.o-p.com/chk/q/$1 [L, R=301]
RewriteCond %{HTTP_HOST} st-iex-t\.o-p\.com$ [NC]
RewriteRule ^/enq/q/(.*) https://st-iex-t.o-p.com/lnk000/=https://st-ex.o-p.com/enq/q/$1 [L, R=301]
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 3