从标题重定向隐藏main.html

时间:2016-09-26 06:59:53

标签: php html .htaccess

我有一个php文件,使用标题重定向到main.html。 我需要在网址中隐藏main.html,看起来像'https://mywebsite.com/main.html`

这样,在显示main.html

的内容时看起来像https://mywebsite.com

1 个答案:

答案 0 :(得分:1)

您可以在根目录中使用这些规则.htaccess:

RewriteEngine On

# if main.html has been sent in original request then redirect to home page
# THE_REQUEST variable represents original request received by Apache from your browser
# and it doesn't get overwritten after execution of some rewrite rules
RewriteCond %{THE_REQUEST} /main\.html[\s?] [NC]
RewriteRule ^main\.html$ / [L,R=301,NC]

# load main.html for landing page
RewriteRule ^/?$ main.html [L]