配置apache的rewrite使整站url都跳转到指定页面

[apache] 2024-04-19 圈点351

摘要:有时候需要配置整站的url都跳转到指定页面,也就是无论访问什么网址都跳转到指定的一个页面。比如:指定所有的泛域名解析的二级域名都跳转到一级域名。

有时候需要配置整站的url都跳转到指定页面,也就是无论访问什么网址都跳转到指定的一个页面。

比如:指定所有的泛域名解析的二级域名都跳转到一级域名。

示例,无论是 x.xoxxoo.com还是x.xoxxoo.com/xxx.html, 都跳转到www.xoxxoo.com首页

逻辑思维: 

先将x.xoxxoo.com域名解析到一个根目录,在根目录下的index.html内容中设置跳转到 www.xoxxoo.com,然后在rewrite模块中设置所有url都跳转到index.html,这样就实现了“二级”跳。


index.html内容如下:

<html>
<head>  
    <meta http-equiv="refresh" content="1;url=http://www.xoxxoo.com">   
</head>
</html>


然后在根目录下创建rewrite规则,意思是无论打开什么内容,都跳转到index.html,内容如下

.htaccess文件内容

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.html [QSA,PT,L]
</IfModule>



rewrite  htaccess  跳转  

感谢反馈,已提交成功,审核后即会显示