Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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 将所有URL重定向到httpd.conf中的单个页面_Apache_Redirect_Httpd.conf - Fatal编程技术网

Apache 将所有URL重定向到httpd.conf中的单个页面

Apache 将所有URL重定向到httpd.conf中的单个页面,apache,redirect,httpd.conf,Apache,Redirect,Httpd.conf,我正在寻找一种方法,重定向到一个单一的域整个网站。我想在httpd.conf文件中执行此操作。例如,我拥有的虚拟主机如下所示: <VirtualHost xx.xx.xx.xx> ServerName website.com ServerAdmin webmaster@website.com ScriptAlias /cgi-bin/ /usr/local/apache2/htdocs/cgi-bin/ DocumentRoot /usr/local/apache2/htdocs/w

我正在寻找一种方法,重定向到一个单一的域整个网站。我想在httpd.conf文件中执行此操作。例如,我拥有的虚拟主机如下所示:

<VirtualHost xx.xx.xx.xx>
ServerName website.com
ServerAdmin webmaster@website.com
ScriptAlias /cgi-bin/ /usr/local/apache2/htdocs/cgi-bin/
DocumentRoot /usr/local/apache2/htdocs/website
CustomLog logs/website/access_log combined
ErrorLog logs/website/error_log
Redirect / http://newwebiste.com
Redirect /xxx http://newwebiste.com
</VirtualHost>

服务器名网站
服务器管理员webmaster@website.com
ScriptAlias/cgi-bin//usr/local/apache2/htdocs/cgi-bin/
DocumentRoot/usr/local/apache2/htdocs/website
自定义日志/网站/访问日志组合
错误日志/网站/错误日志
重定向/http://newwebiste.com
重定向/xxxhttp://newwebiste.com
目前,上面的重定向仍然保留完整的URL

因此,如果我想,我会重定向到。我只想把它放到newwebsite.com上,然后把剩下的丢了

所以

要实现这一点,我需要向httpd.conf添加什么

谢谢,

删除

Redirect / http://newwebiste.com
Redirect /xxx http://newwebiste.com

RewriteRule ^ http://newwebsite.com [L,R=301]

正如您所注意到的,Redirect捕获所有请求并将相同的URI发送到目标,这是您不想要的,因此您将使用RedirectMatch来匹配所有可能的请求,但不向目标url添加任何内容

因此,您只需使用:

重定向匹配^

关于mod_重写的旁注: 我当然不会像其他人推荐的那样推荐mod_rewrite,除非你手头确实有一项任务需要mod_rewrite能够提供的复杂性,而事实并非如此

旁注2:
例如,最好使用“example.com”域名,因为它不是有效的域,并且是永久保留的,用于示例目的。

重新启动httpd服务时,我收到一条无效的命令警告。请参阅/usr/local/apache2/conf/httpd.conf第1526行的以下语法错误:命令“RewriteRule”无效,可能拼写错误或由未包含在服务器配置中的模块定义。我认为需要更新apache服务器。rewrite mod不存在,这就是为什么整个事情都失败了也许你只需要在http.conf中取消注释,看到一个没有mod_rewrite的apache真的很奇怪。推荐mod_rewrite for simpleton重定向是不可取的。这是非常糟糕的建议。