Apache下利用htaccess重定向
站点目录新建.htaccess文件输入如下内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#定义默认首页
DirectoryIndex index.php index.html index.htm
#http跳转https
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
#根域名跳转www
RewriteCond %{http_host} ^baidu.com [NC]
RewriteRule ^(.*)$ https://www.fcwys.cc/$1 [L,R=301]
#子目录跳转
RewriteCond %{HTTP_HOST} ^aaa\.baidu\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/aaa/
RewriteRule ^(.*)$ cjcx/$1?Rewrite [L,QSA]
#自定义404页面
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.html [L]
</IfModule>
#禁止指定文件被查看
<FilesMatch (.*)\.(csv|bak|com|sql|cab|jar|dat|z|db)$>
Order allow,deny
deny from all
</FilesMatch>
注:具体地址和目录根据实际情况修改。