[英]How to redirect website to particular file?
There is a domain name. 有一个域名。 Let's say
domain.com
. 假设
domain.com
。
When the user types domain.com
only, he should be redirected to the address domain.com/file.html
. 当用户仅键入
domain.com
,应将其重定向到地址domain.com/file.html
。 How can I do that with a .htaccess
file? 如何使用
.htaccess
文件执行此操作?
Plus, what does RewriteRule ^index\\.php$ - [L]
mean? 另外,
RewriteRule ^index\\.php$ - [L]
是什么意思? Would it help me? 对我有帮助吗?
添加到您的.htaccess文件
DirectoryIndex file.html
Check out this site: .htaccess tricks and tips It's a good reference for rewrite rules. 查阅以下网站: .htaccess的技巧和窍门这是重写规则的良好参考。
As for what does RewriteRule ^index.php$ - [L] mean. 至于RewriteRule ^ index.php $-[L]是什么意思。 It's going to ignore anything with an index.php ending Rewrite Rule meaning
它会忽略任何以index.php结尾的内容,这是重写规则的含义
To redirect you can make a index page (the first page that the user visits) 要重定向,您可以创建索引页面(用户访问的第一页)
DirectoryIndex file.html
modifying your .htaccess file according to this link . 根据此链接修改.htaccess文件。
For RewriteRule
you need to able the mod_rewrite module in apache and then make in your .htaccess file 对于
RewriteRule
您需要在Apache中启用mod_rewrite模块,然后在.htaccess文件中添加
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*) file.html [L]
</IfModule>
In the RewriteRule
you can put regular expressions to identify the url and redirect the user to a file that you want (in this case you would redirect all your links to file.html
). 在
RewriteRule
您可以放置正则表达式来标识url并将用户重定向到所需的文件(在这种情况下,您将所有链接都重定向到file.html
)。 More info here . 更多信息在这里 。
Moreover in the configuration file of the apache server by default is possible you have the next configuration: 此外,默认情况下,可以在apache服务器的配置文件中进行下一个配置:
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml
</IfModule>
So, by default if you have a file called index.php
in your webroot of your domain.com always that file would be called first. 因此,默认情况下,如果您在domain.com的网络根目录中有一个名为
index.php
的文件,则始终会首先调用该文件。
Try putting the following in your .htaccess file located in the root of domain.com 尝试将以下内容放入位于domain.com根目录的.htaccess文件中
RewriteEngine On
RewriteBase /
#put all the following rules before any other rules in the .htaccess file
RewriteRule ^file\.html$ - [L]
#domain.com or any subdomain
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
#the root of domain
RewriteCond %{REQUEST_URI} ^/?$ [NC]
#return file.html
RewriteRule . file.html [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.