zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Linux apache服务实现URL重定向配置

2023-02-18 16:34:38 时间
URL重定向,

  即将httpd 请求的URL转发至另一个的URL

实现URL重定向的指令:
Redirect [status] URL-path URL
status状态:
  • permanent: 返回永久重定向状态码 301,此重定向信息进行缓存

  • temp:返回临时重定向状态码302. 此为默认值

例如:

[root@centos8 ~]#vim /etc/httpd/conf.d/test.conf 
Redirect permanent / https://www.baidu.com/  #访问本机就跳转到百度   /:表示的是apache网站的根目录
实现http跳转到https

使用Redirect指令这种方法会出现死循环

#注意: RewriteEngine指令需要开启mod_rewrite.so模块
[root@centos8 ~]#vim /etc/httpd/conf.d/test.conf
RewriteEngine on  #启用重写引擎
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=302]

#当发起http请求的时候将地址改为:https://%{HTTP_HOST}$1 [redirect=302]